F#: Using a F# indexed property from C# -


i have written class in f# implementing interface in order build c#-friendly interface f#-assembly.

i have written of properties indexed properties. however, when try use type c#, synthetic get_propertyname methods in intellisense , compiler likewise complains in case want use indexed properties c# ones.

code reference:

type imyinterfacetype =        abstract myproperty : mytype1     abstract myindexedproperty : mytype2 -> mytype3     abstract mytwodimensionalindexedproperty : (mytype4 * mytype5) -> mytype6  type myinterfacetype =         new () = { }      interface imyinterfacetype         member this.myproperty () = new mytype1 ()         member this.myindexedproperty parameter = new mytype3 ()         member this.mytwodimensionalindexedproperty pair = new mytype6 () 

when trying access class c#, methods

get_myindexedproperty(mytype2 parameter) get_mytwodimensionalindexedproperty(tuple<mytype4, mytype5>) 

instead of indexed properties had hoped for.

am doing wrong or known issue?

cheers
--mathias.

response original question:

indexer properties in c# have special name item create indexer accessible c# must name indexer property "item", e.g.:

type x () =     member this.item key = .... 

now can accessed both in f# using (x : x).[key] or in c# using x[key] .

response updated question:

c# not support indexed properties way f# does. instead using additional type advised: https://msdn.microsoft.com/en-us/library/aa288464%28v=vs.71%29.aspx

so can try use this:

[<abstractclass>] type indexer<'index, 'result> () =     abstract : 'index -> 'result     member this.item key = this.get key  type imyinterfacetype =        abstract myproperty : mytype1     // f# indexed propetties     abstract myindexedproperty : mytype2 -> mytype3     // c# workaround     abstract mycsharpindexedproperty : indexer<mytype2, mytype3>  type myinterfacetype () =     let proxy =       { new indexer<mytype2, mytype3> ()           member __.get key = (this :> imyinterfacetype).myindexedproperty key }     interface imyinterfacetype         member __.myproperty () = new mytype1 ()         member __.myindexedproperty key = new mytype3 ()         member __.mycsharpindexedproperty () = proxy 

and 2 dimensional property creating indexer<'index1, 'index2, 'result> () = ...


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -