Reputation: 31
I use my F# Class Library in another C# project. The function I am calling returns an object like this:
type Item =
{ Title: string
Items: List<Item ref> }
The problem is that I when using it in C#, the Items
property is of type List<FSharpRef<Item>>
.
So the question is:
How can I convert it to List<Item>
(in F#) without loosing the references to objects?
i.e. in cases when two Item
objects have a reference to a third one inside their lists, they should refer to the same object in C#.
Upvotes: 3
Views: 203
Reputation: 31
Thanks to everyone who participated in the discussion! The following solutions have emerged:
flatMap
);ref
at all - works fine if the values should be immutable;ref
inside F#, but return an object of another type which doesn't require ref
.I've used the third strategy, since I needed to transform the objects to the other type anyways.
Upvotes: 0
Reputation: 10624
If you want the items to still be inside ref cells in C# then you can keep the F# as it is and dereference each FSharpRef
in C# just before using it with its .Value
property.
Upvotes: 3