public static T Option <T>(this FSharpOption <T> o) where T : class { if (FSharpOption <T> .GetTag(o) == FSharpOption <T> .Tags.None) { return(null); } return(o.Value); }
static void Main(string[] args) { var x = (FSharpOption <T> .GetTag(opt) switch { FSharpOption <T> .Tags.None => "None", FSharpOption <T> .Tags.Some => "Some", _ => "imposibru" });
public void Option() { IsTrue(FSharpOption <int> .get_IsNone(FSharpOption <int> .None)); Equal(FSharpOption <int> .None, null); Equal(FSharpOption <int> .GetTag(FSharpOption <int> .None), 0); Equal(FSharpOption <int> .GetTag(FSharpOption <int> .Some(2)), 1); Equal(FSharpOption <int> .Some(3).Value, 3); Equal(FSharpOption <int> .Some(1), FSharpConvert.Some(1)); Equal(FSharpConvert.Option((int?)1), FSharpOption <int> .Some(1)); }