It appears that the F# compiler should be adding a DefaultMemberAttribute to the class to make the indexer useable from C#. It is not at the moment, so it is a bug in the F# compiler. However fortunately this is easy to fix, by adding the attribute your self:

1
2
3
4
5
6
7
8
[<System.Reflection.DefaultMember("Item")>]
type Foo = class
  val elements: int[]
  member obj.Item
    with get (i) = obj.elements.[i]
    and set (i, v) = obj.elements.[i] <- v
  new () = { elements = Array.create 5 0}
end

I tested this code and it seemed work okay from C#.

However, I think this bug is somewhat forgivable from the F# point of view as the C# spec total fails to mention that the compiler does this!

By on 12/2/2007 8:08 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper