/// <summary> /// Converts a nullable type into an F# option container. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">Input nullable value.</param> /// <returns>An F# option representation of the nullable value.</returns> public static FSharpOption <T> FromNullable <T>(T?value) where T : struct { if (value == null) { return(FSharpOption <T> .None); } return(FSharpOption <T> .Some(value.Value)); }
public static void Remove(Stream source, int id, Stream dest) { var table = Table.Load(new StreamReader(source), new ReadSettings(Delimiter.Comma, false, true, FSharpOption <int> .None, FSharpOption <FSharpFunc <Tuple <int, string>, FSharpOption <Type> > > .Some(FSharpFunc <Tuple <int, string>, FSharpOption <Type> > .FromConverter(tuple => FSharpOption <Type> .Some(typeof(string)))))); var finalTable = Remove(table, id); Table.Save(finalTable, new StreamWriter(dest, new UTF8Encoding(true))); }
/// <summary> /// Converts a value that could potentially be null to an F# option container. /// The return value could either be 'None' or 'Some' which contains a non-null value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">Input value that is nullable.</param> /// <returns>An F# option representation of the nullable value.</returns> public static FSharpOption <T> FromNullable <T>(T value) { if (value == null) { return(FSharpOption <T> .None); } return(FSharpOption <T> .Some(value)); }
public FSharpOption <T> Deserialize(ref JsonReader <TSymbol> reader) { if (reader.ReadIsNull()) { return(null); } return(FSharpOption <T> .Some(elementFormatter.Deserialize(ref reader))); }
public void CanSerializeOption() { var expected = FSharpOption <string> .Some("hello"); Serialize(expected); Reset(); var actual = Deserialize <object>(); expected.ShouldDeepEqual(actual); }
public void CanSerializeOptionalDU() { var expected = DU2.NewE(FSharpOption <DU1> .Some(DU1.NewA(1))); Serialize(expected); Reset(); var actual = Deserialize <object>(); expected.ShouldDeepEqual(actual); }
public override void Setup(BenchmarkContext context) { base.Setup(context); var record = new User( name: "John Doe", aref: FSharpOption <string> .Some("ok"), connections: "test"); InitStreamWith(record); }
public static FSharpOption <T> TryGetTypedProperty <T>(this PropertyCollection col) { T value; if (col.TryGetProperty(typeof(T), out value)) { return(FSharpOption <T> .Some(value)); } return(FSharpOption <T> .None); }