I'm wonder if there is a way to reduce the ugliness of dealing with option types that are returned from F# to C#. For instance:
var result = TheOneCache.Get<Dictionary<Guid, MembershipUser>>(TheOneCache.EntryType.SQL, USERNAME_DICTIONARY);
if (FSharpOption<Dictionary<Guid, MembershipUser>>.get_IsSome(result))
{
result.Value.Remove(membershipid);
}
I'd love to not have to provide the <Dictionary<Guid, MembershipUser>>
every time. Any way to improve this situation?
@MiMo pointed me the right direction in the comments. If anyone else comes across this problem, the following trick from jaredpar' blog will wrap these calls up for you so you can just call FSharpOption.isSome(x)
public static class FSharpOption {
public static FSharpOption<T> Create<T>(T value) {
return new FSharpOption<T>(value);
}
public static bool IsSome<T>(this FSharpOption<T> opt) {
return FSharpOption<T>.get_IsSome(opt);
}
public static bool IsNone<T>(this FSharpOption<T> opt) {
return FSharpOption<T>.get_IsNone(opt);
}
}
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