diff --git a/Base.Tests/Extensions/FSharpExtensionTests.cs b/Base.Tests/Extensions/FSharpExtensionTests.cs deleted file mode 100644 index b2b3aaf..0000000 --- a/Base.Tests/Extensions/FSharpExtensionTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -using FruityFoundation.Base.Extensions; -using FruityFoundation.Base.Structures; -using Microsoft.FSharp.Core; -using NUnit.Framework; - -namespace Base.Tests.Extensions; - -public class FSharpExtensionTests -{ - [Test] - public void TestNoneIntToMaybe() => - Assert.AreEqual(Maybe.Empty(), FSharpOption.None.ToMaybe()); - - [Test] - public void TestSomeIntToMaybe() => - Assert.AreEqual(Maybe.Create(25), FSharpOption.Some(25).ToMaybe()); -} \ No newline at end of file diff --git a/Base/Base.csproj b/Base/Base.csproj index f49b1c4..55cd423 100644 --- a/Base/Base.csproj +++ b/Base/Base.csproj @@ -11,11 +11,7 @@ FruityFoundation.Base https://github.com/kyleratti/FruityFoundation - 1.0.7 + 1.1.0 - - - - diff --git a/Base/Extensions/DataReaderExtensions.cs b/Base/Extensions/DataReaderExtensions.cs new file mode 100644 index 0000000..067bc81 --- /dev/null +++ b/Base/Extensions/DataReaderExtensions.cs @@ -0,0 +1,46 @@ +using System.Data; +using FruityFoundation.Base.Structures; + +namespace FruityFoundation.Base.Extensions; + +public static class DataReaderExtensions +{ + public static Maybe TryGetBoolean(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetBoolean); + + public static Maybe TryGetByte(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetByte); + + public static Maybe TryGetBytes(this IDataReader reader, int ord, long fieldOffset, byte[]? buffer, int bufferOffset, int length) => + TryGet(reader, ord, _ => reader.GetBytes(ord, fieldOffset, buffer, bufferOffset, length)); + + public static Maybe TryGetChars(this IDataReader reader, int ord, long fieldOffset, char[]? buffer, int bufferOffset, int length) => + TryGet(reader, ord, _ => reader.GetChars(ord, fieldOffset, buffer, bufferOffset, length)); + + public static Maybe TryGetDateTime(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetDateTime); + + public static Maybe TryGetDecimal(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetDecimal); + + public static Maybe TryGetFloat(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetFloat); + + public static Maybe TryGetGuid(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetGuid); + + public static Maybe TryGetInt16(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetInt16); + + public static Maybe TryGetInt32(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetInt32); + + public static Maybe TryGetInt64(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetInt64); + + public static Maybe TryGetString(this IDataReader reader, int ord) => + TryGet(reader, ord, reader.GetString); + + private static Maybe TryGet(IDataReader reader, int ord, Func valueGetter) => + reader.IsDBNull(ord) ? Maybe.Empty() : valueGetter(ord); +} \ No newline at end of file diff --git a/Base/Extensions/FSharpExtensions.cs b/Base/Extensions/FSharpExtensions.cs deleted file mode 100644 index 57738d6..0000000 --- a/Base/Extensions/FSharpExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using FruityFoundation.Base.Structures; -using Microsoft.FSharp.Core; - -namespace FruityFoundation.Base.Extensions; - -public static class FSharpExtensions -{ - public static Maybe ToMaybe(this FSharpOption option) => - FSharpOption.get_IsSome(option) - ? Maybe.Create(option.Value) - : Maybe.Empty(); -} \ No newline at end of file diff --git a/Base/Structures/MaybeExtensions.cs b/Base/Structures/MaybeExtensions.cs index 849d89c..55d08cc 100644 --- a/Base/Structures/MaybeExtensions.cs +++ b/Base/Structures/MaybeExtensions.cs @@ -1,6 +1,4 @@ -using Microsoft.FSharp.Core; - -namespace FruityFoundation.Base.Structures; +namespace FruityFoundation.Base.Structures; public static class MaybeExtensions { @@ -9,9 +7,4 @@ public static class MaybeExtensions public static T? ToNullable(this Maybe item) where T : struct => item.HasValue ? item.Value : null; - - public static FSharpOption ToFSharpOption(this Maybe cb) => - cb.HasValue - ? FSharpOption.Some(cb.Value) - : FSharpOption.None; } \ No newline at end of file diff --git a/FruityFoundation.sln b/FruityFoundation.sln index fd25afc..a52733c 100644 --- a/FruityFoundation.sln +++ b/FruityFoundation.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Base.Tests", "Base.Tests\Ba EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Db", "Db\Db.fsproj", "{500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsBase", "FsBase\FsBase.fsproj", "{41607026-96DC-4597-A3C4-E32008F8096F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}.Debug|Any CPU.Build.0 = Debug|Any CPU {500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}.Release|Any CPU.ActiveCfg = Release|Any CPU {500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}.Release|Any CPU.Build.0 = Release|Any CPU + {41607026-96DC-4597-A3C4-E32008F8096F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41607026-96DC-4597-A3C4-E32008F8096F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41607026-96DC-4597-A3C4-E32008F8096F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41607026-96DC-4597-A3C4-E32008F8096F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/FsBase/Extensions.fs b/FsBase/Extensions.fs new file mode 100644 index 0000000..b0a97f3 --- /dev/null +++ b/FsBase/Extensions.fs @@ -0,0 +1,16 @@ +namespace FruityFoundation.FsBase + +open System.Runtime.CompilerServices +open FruityFoundation.Base.Structures + +[] +type Extensions () = + [] + static member ToMaybe (opt : 'a option) = + match opt with + | Some x -> x |> Maybe.Create + | None -> Maybe.Empty () + + [] + static member ToFSharpOption (opt : 'a Maybe) = + if opt.HasValue then Some opt.Value else None \ No newline at end of file diff --git a/FsBase/FsBase.fsproj b/FsBase/FsBase.fsproj new file mode 100644 index 0000000..1f4456e --- /dev/null +++ b/FsBase/FsBase.fsproj @@ -0,0 +1,32 @@ + + + + net6.0 + true + FruityFoundation.FsBase + true + FruityFoundation.FsBase + Kyle Ratti + + + + true + + + + true + + + + + + + + + + + + + + +