public static FSharpValueOption <T> ExecuteQuerySingleVoption <T>(SqlConnection?existingConn, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem) { if (existingConn is not null) { using var cmd = existingConn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (reader.Read()) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); conn.Open(); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (reader.Read()) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else { throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); } }
public void ConvertsFSharpValueOptionValueType() { var fsOpt = FSharpValueOption <int> .NewValueSome(987654); Optional <int> result = fsOpt; result.Should().Be(Optional.Of(987654)); }
public void ConvertsFSharpValueOptionReferenceType() { var fsOpt = FSharpValueOption <string> .NewValueSome("hello world 123"); Optional <string> result = fsOpt; result.Should().Be(Optional.Of("hello world 123")); }
public FSharpValueOption <T> Deserialize(ref JsonReader <TSymbol> reader) { if (reader.ReadIsNull()) { return(FSharpValueOption <T> .ValueNone); } return(FSharpValueOption <T> .NewValueSome(valueFormatter.Deserialize(ref reader))); }
public IViewBuilder ContentMultiple(string property, IEnumerable <Types.IView> content) { var getter = FSharpValueOption <FSharpFunc <TView, object> > .Some(FuncConvert.FromFunc <TView, object>(control => control.Children)); var setter = FSharpValueOption <FSharpFunc <Tuple <TView, object>, Unit> > .None; var list = Microsoft.FSharp.Collections.ListModule.OfSeq(content); Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateContentMultiple(property, getter, setter, list)); return(this); }
public void Serialize(ref JsonWriter <TSymbol> writer, FSharpValueOption <T> value, int nestingLimit) { if (value.IsValueNone) { writer.WriteNull(); return; } valueFormatter.Serialize(ref writer, value.Value, nestingLimit); }
public void RoundTripReferenceThroughFSharpAndBack() { var initial = Optional.Of("nanomachines?!"); FSharpValueOption <string> intermediate = initial.ToFsOption(); intermediate.IsValueSome.Should().BeTrue(); Optional <string> result = intermediate; result.Should().Be(Optional.Of("nanomachines?!")); }
public void RoundTripEmptyValueTypeThroughFSharpAndBack() { var initial = Optional <int> .Empty; FSharpValueOption <int> intermediate = initial.ToFsOption(); intermediate.IsValueNone.Should().BeTrue(); Optional <int> result = intermediate; result.Should().Be(Optional <int> .Empty); }
public void RoundTripValueTypeThroughFSharpAndBack() { var initial = Optional.Of(1337.1337); FSharpValueOption <double> intermediate = initial.ToFsOption(); intermediate.IsValueSome.Should().BeTrue(); Optional <double> result = intermediate; result.Should().Be(Optional.Of(1337.1337)); }
public void Serialize(ref MessagePackWriter writer, FSharpValueOption <T> value, MessagePackSerializerOptions options) { if (value.IsNone) { writer.WriteNil(); return; } else { IFormatterResolver resolver = options.Resolver; resolver.GetFormatterWithVerify <T>().Serialize(ref writer, value.Value, options); } }
public FSharpValueOption <T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return(FSharpValueOption <T> .None); } IFormatterResolver resolver = options.Resolver; options.Security.DepthStep(ref reader); T value = resolver.GetFormatterWithVerify <T>().Deserialize(ref reader, options);; reader.Depth--; return(FSharpValueOption <T> .Some(value)); }
public IViewBuilder Property <TValue>(string property, TValue value, Func <TView, TValue> getter, Action <TView, TValue> setter, Func <TValue, TValue, bool> comparer) { var cmp = comparer == null ? FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .None : FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .Some(FuncConvert.FromFunc <Tuple <object, object>, bool>(t => comparer((TValue)t.Item1, (TValue)t.Item2))); var get = getter == null ? FSharpValueOption <FSharpFunc <TView, TValue> > .None : FSharpValueOption <FSharpFunc <TView, TValue> > .Some(FuncConvert.FromFunc(getter)); var set = setter == null ? FSharpValueOption <FSharpFunc <Tuple <TView, TValue>, Unit> > .None : FSharpValueOption <FSharpFunc <Tuple <TView, TValue>, Unit> > .Some(FuncConvert.FromAction <Tuple <TView, TValue> >(tup => setter(tup.Item1, tup.Item2))); Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateProperty(property, value, get, set, cmp)); return(this); }
public static async Task <FSharpValueOption <T> > ExecuteQuerySingleAsyncVoption <T>(SqlConnection?existingConn, SqlTransaction?tran, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, IEnumerable <TempTableData> tempTableData, CancellationToken ct) { if (existingConn is not null) { await LoadTempTablesAsync(existingConn, tempTableData, tran, ct); await using var cmd = existingConn.CreateCommand(); ConfigureCommand(cmd, tran, configureCmd); await using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (!await reader.ReadAsync(ct).ConfigureAwait(false)) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } // ReSharper disable once InvertIf if (connStr is not null) { await using var conn = new SqlConnection(connStr); configureNewConn(conn); await conn.OpenAsync(ct).ConfigureAwait(false); await LoadTempTablesAsync(conn, tempTableData, tran, ct); await using var cmd = conn.CreateCommand(); configureCmd(cmd); await using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (!await reader.ReadAsync(ct).ConfigureAwait(false)) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); }
public static async Task <FSharpValueOption <T> > ExecuteQuerySingleAsyncVoption <T>(SqlConnection?existingConn, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, CancellationToken ct) { if (existingConn is not null) { using var cmd = existingConn.CreateCommand(); configureCmd(cmd); using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (await reader.ReadAsync(ct).ConfigureAwait(false)) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); await conn.OpenAsync(ct).ConfigureAwait(false); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow, ct).ConfigureAwait(false); if (await reader.ReadAsync(ct).ConfigureAwait(false)) { initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } return(FSharpValueOption <T> .None); } else { throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); } }
public static FSharpValueOption <T> ExecuteQuerySingleVoption <T>(SqlConnection?existingConn, SqlTransaction?tran, string?connStr, Action <SqlConnection> configureNewConn, Action <SqlCommand> configureCmd, Action <SqlDataReader> initOrdinals, Func <SqlDataReader, T> getItem, IEnumerable <TempTableData> tempTableData) { if (existingConn is not null) { LoadTempTables(existingConn, tempTableData, tran); using var cmd = existingConn.CreateCommand(); ConfigureCommand(cmd, tran, configureCmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (!reader.Read()) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } // ReSharper disable once InvertIf if (connStr is not null) { using var conn = new SqlConnection(connStr); configureNewConn(conn); conn.Open(); LoadTempTables(conn, tempTableData, tran); using var cmd = conn.CreateCommand(); configureCmd(cmd); using var reader = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow); if (!reader.Read()) { return(FSharpValueOption <T> .None); } initOrdinals(reader); return(FSharpValueOption <T> .Some(getItem(reader))); } throw new Exception($"{nameof(existingConn)} and {nameof(connStr)} may not both be null"); }
public IViewBuilder Property <TValue>(AvaloniaProperty property, TValue value, Func <TValue, TValue, bool> comparer) { Attrs.Add(Avalonia.FuncUI.Builder.AttrBuilder <TView> .CreateProperty(property, value, FSharpValueOption <FSharpFunc <Tuple <object, object>, bool> > .Some(FuncConvert.FromFunc <Tuple <object, object>, bool>(t => comparer((TValue)t.Item1, (TValue)t.Item2))))); return(this); }