2 Commits

Author SHA1 Message Date
57e83fbafa removed some new lang features to support net6.0 and net7.0
All checks were successful
.NET Test / test (push) Successful in 1m5s
.NET Publish / publish (push) Successful in 51s
2023-12-15 12:37:39 +04:00
c02fdc5492 added more nuget info
All checks were successful
.NET Test / test (push) Successful in 29m24s
.NET Publish / publish (push) Successful in 10m18s
2023-12-13 20:15:56 +04:00
8 changed files with 84 additions and 61 deletions

View File

@@ -35,4 +35,4 @@ jobs:
run: dotnet nuget push --source gitea_registry --api-key ${{ secrets.LOCAL_NUGET_PACKAGE_TOKEN }} nupkgs/*.nupkg
- name: Publish the package to NuGet.org
run: dotnet nuget push --api-key ${{ secrets.NUGET_PACKAGE_TOKEN }} nupkgs/*.nupkg
run: dotnet nuget push --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_PACKAGE_TOKEN }} nupkgs/*.nupkg

View File

@@ -60,6 +60,7 @@ public readonly struct Ensure<T>
Value = value;
ValueExpression = valueExpression;
State = ResultState.Success;
Error = default;
}
internal Ensure(Error error, string valueExpression)
@@ -72,7 +73,12 @@ public readonly struct Ensure<T>
}
[Serializable]
public class EnsureNotInitializedException(string variableName = "this") : InvalidOperationException("Ensure was not properly initialized.")
public class EnsureNotInitializedException : InvalidOperationException
{
public string VariableName { get; } = variableName;
public EnsureNotInitializedException(string variableName = "this")
: base("Ensure was not properly initialized.")
{
VariableName = variableName;
}
public string VariableName { get; }
}

View File

@@ -52,7 +52,7 @@ public abstract class Error : IEquatable<Error>, IComparable<Error>
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Error Many(Error error1, Error error2) => (error1, error2) switch
{
(null, null) => new ManyErrors([]),
(null, null) => new ManyErrors(new List<Error>()),
(Error err, null) => err,
(Error err, { IsEmpty: true }) => err,
(null, Error err) => err,
@@ -231,7 +231,7 @@ public sealed class ExceptionalError : Error
var valueString = value.ToString();
if (string.IsNullOrEmpty(keyString) || string.IsNullOrEmpty(valueString)) continue;
values ??= [];
values ??= new List<KeyValuePair<string, string>>(4);
values.Add(new(keyString, valueString));
}
return values?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty;
@@ -377,7 +377,11 @@ public sealed class ManyErrors : Error, IEnumerable<Error>, IReadOnlyList<Error>
}
[Serializable]
public sealed class ErrorException(string type, string message) : Exception(message)
public sealed class ErrorException : Exception
{
public string Type { get; } = type ?? nameof(ErrorException);
public ErrorException(string type, string message) : base(message)
{
Type = type ?? nameof(ErrorException);
}
public string Type { get; }
}

View File

@@ -35,7 +35,7 @@ public sealed class ErrorJsonConverter : JsonConverter<Error>
internal static ManyErrors ReadMany(ref Utf8JsonReader reader)
{
List<Error> errors = [];
List<Error> errors = new(4);
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.StartObject)
@@ -83,7 +83,7 @@ public sealed class ErrorJsonConverter : JsonConverter<Error>
}
else if (!string.IsNullOrEmpty(propname))
{
extensionData ??= [];
extensionData ??= new(4);
extensionData.Add(new(propname, propvalue));
}

View File

@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Just.Railway</AssemblyName>
@@ -11,7 +12,8 @@
<PackageTags>railway-oriented;functional;result-pattern;result-object;error-handling</PackageTags>
<Authors>JustFixMe</Authors>
<Copyright>Copyright (c) 2023 JustFixMe</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/JustFixMe/Just.Railway/</RepositoryUrl>
<EmitCompilerGeneratedFiles Condition="'$(Configuration)'=='Debug'">true</EmitCompilerGeneratedFiles>
@@ -26,6 +28,11 @@
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath=""/>
<None Include="..\LICENSE" Pack="true" Visible="false" PackagePath=""/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Railway.SourceGenerator\Railway.SourceGenerator.csproj"
OutputItemType="Analyzer"

View File

@@ -10,9 +10,8 @@ internal static class ReflectionHelper
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Compare<T>(T? left, T? right) => TypeReflectionCache<T>.CompareFunc(left, right);
}
file static class TypeReflectionCache<T>
private static class TypeReflectionCache<T>
{
public static readonly Func<T?, T?, bool> IsEqualFunc;
public static readonly Func<T?, T?, int> CompareFunc;
@@ -65,3 +64,4 @@ file static class TypeReflectionCache<T>
: right is null ? 1 : left.Value.CompareTo(right.Value);
#pragma warning restore CS8604 // Possible null reference argument.
}
}

View File

@@ -136,6 +136,7 @@ public readonly struct Result<T> : IEquatable<Result<T>>
{
Value = value;
State = ResultState.Success;
Error = default;
}
[Pure] public static explicit operator Result(Result<T> result) => result.State switch
@@ -263,7 +264,12 @@ public readonly struct SuccessUnit : IEquatable<SuccessUnit>
}
[Serializable]
public class ResultNotInitializedException(string variableName = "this") : InvalidOperationException("Result was not properly initialized.")
public class ResultNotInitializedException : InvalidOperationException
{
public string VariableName { get; } = variableName;
public ResultNotInitializedException(string variableName = "this")
: base("Result was not properly initialized.")
{
VariableName = variableName;
}
public string VariableName { get; }
}

View File

@@ -89,7 +89,7 @@ public static partial class ResultExtensions
{
case ResultState.Error:
hasErrors = true;
errors ??= [];
errors ??= new(4);
errors.Add(result.Error!);
break;
@@ -123,13 +123,13 @@ public static partial class ResultExtensions
{
case ResultState.Error:
hasErrors = true;
errors ??= [];
errors ??= new(4);
errors.Add(result.Error!);
break;
case ResultState.Success:
if (hasErrors) goto afterLoop;
values ??= [];
values ??= new(4);
values.Add(result.Value);
break;