I am currently interoperating with C# code from F#.
Is it possible in F# to define a property that in C# looks like below?
private Func<PropertyInfo, bool> OnIsSatisfiedByProperty { get; set; }
(In F# it wouldn't have to be Func<T, TResult>
but something equivalent.)
If you need to interop with the type from C#, you def want it to be a Func<T>
as opposed to FSharpFunc
which has extra metadata such as non-null
stipulations [as my earlier comments and @John Palmer's answer ends up being]. Hence the shortest similar actual equivalent you can init with an object-initializer is:
type MyType()=
member val public OnIsSatisfiedByProperty : Func<PropertyInfo,bool> = null with get,set
or you could go down the route of:
type MyType()=
[<DefaultValue()>]val mutable OnIsSatisfiedByProperty : Func<System.Reflection.PropertyInfo,bool>
but my quick messing about leaves me needing to impl explicit set/get methods in that case.
(BTW I knew this answer only due to conincidentally a few mins back, a fixture.Inject( fun () -> !value)
wasnt working the same way as fixture.Inject<Func<MyValue>>( fun () -> !value)
!)
I think the equivalent would be something like
type test() =
member val private OnIsSatisfiedByProperty:PropertyInfo -> bool = (fun _ -> true) with get,set;;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With