feat: move FSharp stuff into FsBase
This drops the FSharp.Core dependency on FruityFoundation.Base
This commit is contained in:
parent
224b3eb4a3
commit
e12137b302
|
@ -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<int>.Empty(), FSharpOption<int>.None.ToMaybe());
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestSomeIntToMaybe() =>
|
|
||||||
Assert.AreEqual(Maybe<int>.Create(25), FSharpOption<int>.Some(25).ToMaybe());
|
|
||||||
}
|
|
|
@ -11,11 +11,7 @@
|
||||||
<Company />
|
<Company />
|
||||||
<Product>FruityFoundation.Base</Product>
|
<Product>FruityFoundation.Base</Product>
|
||||||
<RepositoryUrl>https://github.com/kyleratti/FruityFoundation</RepositoryUrl>
|
<RepositoryUrl>https://github.com/kyleratti/FruityFoundation</RepositoryUrl>
|
||||||
<PackageVersion>1.0.7</PackageVersion>
|
<PackageVersion>1.1.0</PackageVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="FSharp.Core" Version="6.0.3" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
46
Base/Extensions/DataReaderExtensions.cs
Normal file
46
Base/Extensions/DataReaderExtensions.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
using System.Data;
|
||||||
|
using FruityFoundation.Base.Structures;
|
||||||
|
|
||||||
|
namespace FruityFoundation.Base.Extensions;
|
||||||
|
|
||||||
|
public static class DataReaderExtensions
|
||||||
|
{
|
||||||
|
public static Maybe<bool> TryGetBoolean(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetBoolean);
|
||||||
|
|
||||||
|
public static Maybe<byte> TryGetByte(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetByte);
|
||||||
|
|
||||||
|
public static Maybe<long> 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<long> 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<DateTime> TryGetDateTime(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetDateTime);
|
||||||
|
|
||||||
|
public static Maybe<decimal> TryGetDecimal(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetDecimal);
|
||||||
|
|
||||||
|
public static Maybe<float> TryGetFloat(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetFloat);
|
||||||
|
|
||||||
|
public static Maybe<Guid> TryGetGuid(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetGuid);
|
||||||
|
|
||||||
|
public static Maybe<short> TryGetInt16(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetInt16);
|
||||||
|
|
||||||
|
public static Maybe<int> TryGetInt32(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetInt32);
|
||||||
|
|
||||||
|
public static Maybe<long> TryGetInt64(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetInt64);
|
||||||
|
|
||||||
|
public static Maybe<string> TryGetString(this IDataReader reader, int ord) =>
|
||||||
|
TryGet(reader, ord, reader.GetString);
|
||||||
|
|
||||||
|
private static Maybe<T> TryGet<T>(IDataReader reader, int ord, Func<int, T> valueGetter) =>
|
||||||
|
reader.IsDBNull(ord) ? Maybe<T>.Empty() : valueGetter(ord);
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
using FruityFoundation.Base.Structures;
|
|
||||||
using Microsoft.FSharp.Core;
|
|
||||||
|
|
||||||
namespace FruityFoundation.Base.Extensions;
|
|
||||||
|
|
||||||
public static class FSharpExtensions
|
|
||||||
{
|
|
||||||
public static Maybe<T> ToMaybe<T>(this FSharpOption<T> option) =>
|
|
||||||
FSharpOption<T>.get_IsSome(option)
|
|
||||||
? Maybe<T>.Create(option.Value)
|
|
||||||
: Maybe<T>.Empty();
|
|
||||||
}
|
|
|
@ -1,6 +1,4 @@
|
||||||
using Microsoft.FSharp.Core;
|
namespace FruityFoundation.Base.Structures;
|
||||||
|
|
||||||
namespace FruityFoundation.Base.Structures;
|
|
||||||
|
|
||||||
public static class MaybeExtensions
|
public static class MaybeExtensions
|
||||||
{
|
{
|
||||||
|
@ -9,9 +7,4 @@ public static class MaybeExtensions
|
||||||
|
|
||||||
public static T? ToNullable<T>(this Maybe<T> item) where T : struct =>
|
public static T? ToNullable<T>(this Maybe<T> item) where T : struct =>
|
||||||
item.HasValue ? item.Value : null;
|
item.HasValue ? item.Value : null;
|
||||||
|
|
||||||
public static FSharpOption<T> ToFSharpOption<T>(this Maybe<T> cb) =>
|
|
||||||
cb.HasValue
|
|
||||||
? FSharpOption<T>.Some(cb.Value)
|
|
||||||
: FSharpOption<T>.None;
|
|
||||||
}
|
}
|
|
@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Base.Tests", "Base.Tests\Ba
|
||||||
EndProject
|
EndProject
|
||||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Db", "Db\Db.fsproj", "{500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}"
|
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Db", "Db\Db.fsproj", "{500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsBase", "FsBase\FsBase.fsproj", "{41607026-96DC-4597-A3C4-E32008F8096F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{500FBEA7-C8FB-44EC-AAFD-B21FAFF08E93}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
16
FsBase/Extensions.fs
Normal file
16
FsBase/Extensions.fs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
namespace FruityFoundation.FsBase
|
||||||
|
|
||||||
|
open System.Runtime.CompilerServices
|
||||||
|
open FruityFoundation.Base.Structures
|
||||||
|
|
||||||
|
[<Extension>]
|
||||||
|
type Extensions () =
|
||||||
|
[<Extension>]
|
||||||
|
static member ToMaybe (opt : 'a option) =
|
||||||
|
match opt with
|
||||||
|
| Some x -> x |> Maybe.Create
|
||||||
|
| None -> Maybe.Empty ()
|
||||||
|
|
||||||
|
[<Extension>]
|
||||||
|
static member ToFSharpOption (opt : 'a Maybe) =
|
||||||
|
if opt.HasValue then Some opt.Value else None
|
32
FsBase/FsBase.fsproj
Normal file
32
FsBase/FsBase.fsproj
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<RootNamespace>FruityFoundation.FsBase</RootNamespace>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<PackageId>FruityFoundation.FsBase</PackageId>
|
||||||
|
<Authors>Kyle Ratti</Authors>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Extensions.fs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Update="FSharp.Core" Version="6.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Base\Base.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user