From 1b2c028180d5161b4b0e2dc124dfbd6396b3f546 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Sun, 19 Nov 2023 11:26:11 +0000 Subject: [PATCH] Update sdk to .NET 8 --- .editorconfig | 7 +++++ Directory.Build.props | 18 ++---------- Directory.packages.props | 24 +++++++++++++++ Dockerfile | 2 +- .../Eff.Examples.AspNetCore.csproj | 10 +++---- .../EffBindings/EffectLogger.cs | 2 +- .../EffBindings/ReplayTokenHeaderHelpers.cs | 2 +- .../Eff.Examples.CancellationToken.csproj | 2 +- .../Eff.Examples.Config.csproj | 4 +-- .../Eff.Examples.Console.csproj | 2 +- .../Eff.Examples.Continuation.csproj | 2 +- .../Eff.Examples.DependencyInjection.csproj | 2 +- .../Eff.Examples.Maybe.csproj | 3 +- .../Eff.Examples.NonDeterminism.csproj | 2 +- .../Eff.Examples.RecordReplay.csproj | 3 +- .../Eff.Examples.Resumable.csproj | 3 +- .../Eff.Examples.StackTrace.csproj | 2 +- .../Eff.Examples.TraceLog.csproj | 2 +- src/Directory.Build.props | 29 +++++++++++++++++++ .../DependencyInjection/DependencyEffect.cs | 4 +-- src/Eff/Eff.csproj | 14 ++++++--- src/Eff/Handlers/EffAwaiter.cs | 4 +-- src/Eff/Handlers/EffectHandler.cs | 2 +- src/Eff/Unit.cs | 4 +-- src/Eff/Utils/TraceHelpers.cs | 25 ++++++++-------- src/Eff/Utils/ValueTaskPromise.cs | 8 ++--- tests/Eff.Benchmarks/Eff.Benchmarks.csproj | 6 ++-- tests/Eff.Tests/CustomEffectHandlerTests.cs | 10 +++---- tests/Eff.Tests/Eff.Tests.csproj | 10 +++---- 29 files changed, 129 insertions(+), 79 deletions(-) create mode 100644 .editorconfig create mode 100644 Directory.packages.props create mode 100644 src/Directory.Build.props diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..83e29fd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*.cs] + +# CA1000: Do not declare static members on generic types +dotnet_diagnostic.CA1000.severity = none + +# CA1865: Use 'string.Method(char)' instead of 'string.Method(string)' for string with single char +dotnet_diagnostic.CA1865.severity = none \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index e7f0ef4..ed3fe26 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,19 +1,7 @@ - + - false - snupkg - true - Nessos Information Technologies - Nessos Information Technologies - Nessos Information Technologies - https://github.com/nessos/Eff - MIT - git - false - Programming with effects and handlers in C# - https://github.com/nessos/Eff/blob/master/CHANGELOG.md - Copyright 2020 - C# effects handlers enable + 12.0 + false diff --git a/Directory.packages.props b/Directory.packages.props new file mode 100644 index 0000000..717c55e --- /dev/null +++ b/Directory.packages.props @@ -0,0 +1,24 @@ + + + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 95420fa..71da33c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine3.14 +FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine RUN apk add git make diff --git a/samples/Eff.Examples.AspNetCore/Eff.Examples.AspNetCore.csproj b/samples/Eff.Examples.AspNetCore/Eff.Examples.AspNetCore.csproj index 07bc08d..5b35c2c 100644 --- a/samples/Eff.Examples.AspNetCore/Eff.Examples.AspNetCore.csproj +++ b/samples/Eff.Examples.AspNetCore/Eff.Examples.AspNetCore.csproj @@ -1,19 +1,19 @@  - net6.0 Exe - enable + net8.0 CS1998;CS1591;$(NoWarn) true + false true - - - + + + diff --git a/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs b/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs index 60eb64d..ccee578 100644 --- a/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs +++ b/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs @@ -83,7 +83,7 @@ public void WriteToAwaiter(EffAwaiter awaiter) if (IsException) { var exn = JsonConvert.DeserializeObject(Value); - awaiter.SetException(exn); + awaiter.SetException(exn!); } else { diff --git a/samples/Eff.Examples.AspNetCore/EffBindings/ReplayTokenHeaderHelpers.cs b/samples/Eff.Examples.AspNetCore/EffBindings/ReplayTokenHeaderHelpers.cs index ffbd039..269f55f 100644 --- a/samples/Eff.Examples.AspNetCore/EffBindings/ReplayTokenHeaderHelpers.cs +++ b/samples/Eff.Examples.AspNetCore/EffBindings/ReplayTokenHeaderHelpers.cs @@ -24,7 +24,7 @@ public static class ReplayTokenHeaderHelpers public static void AddReplayTokenHeader(this HttpResponse response, string replayToken) { - response.Headers.Add(EffReplayTokenHeaderName, replayToken); + response.Headers.Append(EffReplayTokenHeaderName, replayToken); } } diff --git a/samples/Eff.Examples.CancellationToken/Eff.Examples.CancellationToken.csproj b/samples/Eff.Examples.CancellationToken/Eff.Examples.CancellationToken.csproj index 390a50f..c934b2e 100644 --- a/samples/Eff.Examples.CancellationToken/Eff.Examples.CancellationToken.csproj +++ b/samples/Eff.Examples.CancellationToken/Eff.Examples.CancellationToken.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Exe diff --git a/samples/Eff.Examples.Config/Eff.Examples.Config.csproj b/samples/Eff.Examples.Config/Eff.Examples.Config.csproj index a44d76f..3951e92 100644 --- a/samples/Eff.Examples.Config/Eff.Examples.Config.csproj +++ b/samples/Eff.Examples.Config/Eff.Examples.Config.csproj @@ -1,12 +1,12 @@  - net6.0 + net8.0 Exe - + diff --git a/samples/Eff.Examples.Console/Eff.Examples.Console.csproj b/samples/Eff.Examples.Console/Eff.Examples.Console.csproj index 932e7cf..0e8dd6b 100644 --- a/samples/Eff.Examples.Console/Eff.Examples.Console.csproj +++ b/samples/Eff.Examples.Console/Eff.Examples.Console.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe diff --git a/samples/Eff.Examples.Continuation/Eff.Examples.Continuation.csproj b/samples/Eff.Examples.Continuation/Eff.Examples.Continuation.csproj index 996b07d..68818f5 100644 --- a/samples/Eff.Examples.Continuation/Eff.Examples.Continuation.csproj +++ b/samples/Eff.Examples.Continuation/Eff.Examples.Continuation.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 diff --git a/samples/Eff.Examples.DependencyInjection/Eff.Examples.DependencyInjection.csproj b/samples/Eff.Examples.DependencyInjection/Eff.Examples.DependencyInjection.csproj index 390a50f..c934b2e 100644 --- a/samples/Eff.Examples.DependencyInjection/Eff.Examples.DependencyInjection.csproj +++ b/samples/Eff.Examples.DependencyInjection/Eff.Examples.DependencyInjection.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Exe diff --git a/samples/Eff.Examples.Maybe/Eff.Examples.Maybe.csproj b/samples/Eff.Examples.Maybe/Eff.Examples.Maybe.csproj index 813b218..0e8dd6b 100644 --- a/samples/Eff.Examples.Maybe/Eff.Examples.Maybe.csproj +++ b/samples/Eff.Examples.Maybe/Eff.Examples.Maybe.csproj @@ -1,9 +1,8 @@  - net6.0 + net8.0 Exe - enable diff --git a/samples/Eff.Examples.NonDeterminism/Eff.Examples.NonDeterminism.csproj b/samples/Eff.Examples.NonDeterminism/Eff.Examples.NonDeterminism.csproj index 932e7cf..0e8dd6b 100644 --- a/samples/Eff.Examples.NonDeterminism/Eff.Examples.NonDeterminism.csproj +++ b/samples/Eff.Examples.NonDeterminism/Eff.Examples.NonDeterminism.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe diff --git a/samples/Eff.Examples.RecordReplay/Eff.Examples.RecordReplay.csproj b/samples/Eff.Examples.RecordReplay/Eff.Examples.RecordReplay.csproj index 813b218..0e8dd6b 100644 --- a/samples/Eff.Examples.RecordReplay/Eff.Examples.RecordReplay.csproj +++ b/samples/Eff.Examples.RecordReplay/Eff.Examples.RecordReplay.csproj @@ -1,9 +1,8 @@  - net6.0 + net8.0 Exe - enable diff --git a/samples/Eff.Examples.Resumable/Eff.Examples.Resumable.csproj b/samples/Eff.Examples.Resumable/Eff.Examples.Resumable.csproj index 7d92492..7ee7b13 100644 --- a/samples/Eff.Examples.Resumable/Eff.Examples.Resumable.csproj +++ b/samples/Eff.Examples.Resumable/Eff.Examples.Resumable.csproj @@ -2,9 +2,8 @@ Exe - net6.0 + net8.0 enable - enable diff --git a/samples/Eff.Examples.StackTrace/Eff.Examples.StackTrace.csproj b/samples/Eff.Examples.StackTrace/Eff.Examples.StackTrace.csproj index 932e7cf..0e8dd6b 100644 --- a/samples/Eff.Examples.StackTrace/Eff.Examples.StackTrace.csproj +++ b/samples/Eff.Examples.StackTrace/Eff.Examples.StackTrace.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe diff --git a/samples/Eff.Examples.TraceLog/Eff.Examples.TraceLog.csproj b/samples/Eff.Examples.TraceLog/Eff.Examples.TraceLog.csproj index 932e7cf..0e8dd6b 100644 --- a/samples/Eff.Examples.TraceLog/Eff.Examples.TraceLog.csproj +++ b/samples/Eff.Examples.TraceLog/Eff.Examples.TraceLog.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..6632341 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,29 @@ + + + + + latest-recommended + true + true + true + Nullable + 9999 + true + + + + snupkg + true + Nessos Information Technologies + Nessos Information Technologies + Nessos Information Technologies + https://github.com/nessos/Eff + MIT + git + false + Programming with effects and handlers in C# + https://github.com/nessos/Eff/blob/master/CHANGELOG.md + Copyright 2020 + C# effects handlers + + \ No newline at end of file diff --git a/src/Eff/Applications/DependencyInjection/DependencyEffect.cs b/src/Eff/Applications/DependencyInjection/DependencyEffect.cs index b261af0..d689352 100644 --- a/src/Eff/Applications/DependencyInjection/DependencyEffect.cs +++ b/src/Eff/Applications/DependencyInjection/DependencyEffect.cs @@ -15,7 +15,7 @@ public abstract class DependencyEffect : Effect public abstract ValueTask Handle(IContainer container); } - internal class FuncDependencyEffect : DependencyEffect + internal sealed class FuncDependencyEffect : DependencyEffect { public Func> Func { get; } @@ -31,7 +31,7 @@ public override ValueTask Handle(IContainer container) } } - internal class ContainerFuncDependencyEffect : DependencyEffect + internal sealed class ContainerFuncDependencyEffect : DependencyEffect { public Func> Func { get; } diff --git a/src/Eff/Eff.csproj b/src/Eff/Eff.csproj index 9f5dde2..b2930da 100644 --- a/src/Eff/Eff.csproj +++ b/src/Eff/Eff.csproj @@ -5,16 +5,22 @@ netstandard2.0;netstandard2.1 Programming with effects and handlers in C# true - 10.0 true - - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + - + diff --git a/src/Eff/Handlers/EffAwaiter.cs b/src/Eff/Handlers/EffAwaiter.cs index d2192b8..5c3682a 100644 --- a/src/Eff/Handlers/EffAwaiter.cs +++ b/src/Eff/Handlers/EffAwaiter.cs @@ -31,7 +31,7 @@ internal EffAwaiter() { } /// /// Gets or sets the line number at the source file at which the method is called. /// - public int CallerLineNumber { get; set; } = 0; + public int CallerLineNumber { get; set; } /// /// Returns true if the awaiter has been completed with a result value. @@ -122,7 +122,7 @@ public void GetResult() /// Result type required by the awaiter. public abstract class EffAwaiter : EffAwaiter { - private TResult? _result = default; + private TResult? _result; /// /// Gets either the result value or throws the exception that have been stored in the awaiter. diff --git a/src/Eff/Handlers/EffectHandler.cs b/src/Eff/Handlers/EffectHandler.cs index 02176dc..83a22f1 100644 --- a/src/Eff/Handlers/EffectHandler.cs +++ b/src/Eff/Handlers/EffectHandler.cs @@ -58,7 +58,7 @@ public virtual async ValueTask Handle(EffStateMachine stateMac default: Debug.Fail($"Unrecognized state machine position {stateMachine.Position}."); - throw new Exception($"Internal error: unrecognized state machine position {stateMachine.Position}."); + throw new InvalidOperationException($"Internal error: unrecognized state machine position {stateMachine.Position}."); } } } diff --git a/src/Eff/Unit.cs b/src/Eff/Unit.cs index b25007c..202fce1 100644 --- a/src/Eff/Unit.cs +++ b/src/Eff/Unit.cs @@ -14,11 +14,11 @@ namespace Nessos.Effects /// /// Gets the Unit instance. /// - public static Unit Value => new Unit(); + public static Unit Value => new(); /// Implements unit hashcode public override int GetHashCode() => 1; /// Implements unit equality - public override bool Equals(object other) => other is Unit; + public override bool Equals(object? obj) => obj is Unit; /// Implements unit equality public bool Equals(Unit other) => true; /// Implements unit equality diff --git a/src/Eff/Utils/TraceHelpers.cs b/src/Eff/Utils/TraceHelpers.cs index 456a0fd..21d7914 100644 --- a/src/Eff/Utils/TraceHelpers.cs +++ b/src/Eff/Utils/TraceHelpers.cs @@ -27,22 +27,21 @@ private static (string name, FieldInfo fieldInfo)[] GetParametersInfo(object sta { var fieldInfos = state.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - var parametersInfo = fieldInfos - .Where(fieldInfo => !fieldInfo.Name.StartsWith("<")) - .Select(fieldInfo => (fieldInfo.Name, fieldInfo)) - .ToArray(); - return parametersInfo; + return fieldInfos + .Where(fieldInfo => !fieldInfo.Name.StartsWith("<", StringComparison.Ordinal)) + .Select(fieldInfo => (fieldInfo.Name, fieldInfo)) + .ToArray(); } + private static (string name, FieldInfo fieldInfo)[] GetLocalVariablesInfo(object state) { var fieldInfos = state.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - var localVariablesInfo = fieldInfos - .Where(fieldInfo => !fieldInfo.Name.StartsWith("<>")) - .Where(fieldInfo => fieldInfo.Name.StartsWith("<")) - .Select(fieldInfo => (fieldInfo.Name.Substring(1, fieldInfo.Name.LastIndexOf(">") - 1), fieldInfo)) - .ToArray(); - return localVariablesInfo; + return fieldInfos + .Where(fieldInfo => !fieldInfo.Name.StartsWith("<>", StringComparison.Ordinal)) + .Where(fieldInfo => fieldInfo.Name.StartsWith("<", StringComparison.Ordinal)) + .Select(fieldInfo => (fieldInfo.Name[1..fieldInfo.Name.LastIndexOf('>')], fieldInfo)) + .ToArray(); } /// @@ -95,8 +94,8 @@ public static string GetMethodName(this IAsyncStateMachine stateMachine) } var name = stateMachine.GetType().Name; - if (name.StartsWith("<")) - return name.Substring(1, name.LastIndexOf(">") - 1); + if (name.StartsWith("<", StringComparison.Ordinal)) + return name[1..name.LastIndexOf('>')]; else return name; } diff --git a/src/Eff/Utils/ValueTaskPromise.cs b/src/Eff/Utils/ValueTaskPromise.cs index 8494798..a4f0e91 100644 --- a/src/Eff/Utils/ValueTaskPromise.cs +++ b/src/Eff/Utils/ValueTaskPromise.cs @@ -20,10 +20,10 @@ private struct ContinuationContext public object? Scheduler; } - private volatile int _isTaskCompleted = 0; - private volatile int _subscriptionsInProgress = 0; - private volatile int _isFirstContinuationQueued = 0; - private ContinuationContext _firstContinuation = default; + private volatile int _isTaskCompleted; + private volatile int _subscriptionsInProgress; + private volatile int _isFirstContinuationQueued; + private ContinuationContext _firstContinuation; private ConcurrentQueue? _additionalContinuations; public ValueTask Task => new ValueTask(this, 0); diff --git a/tests/Eff.Benchmarks/Eff.Benchmarks.csproj b/tests/Eff.Benchmarks/Eff.Benchmarks.csproj index 67aa111..f47f359 100644 --- a/tests/Eff.Benchmarks/Eff.Benchmarks.csproj +++ b/tests/Eff.Benchmarks/Eff.Benchmarks.csproj @@ -1,13 +1,13 @@  - net6.0 + net8.0 Exe - - + + diff --git a/tests/Eff.Tests/CustomEffectHandlerTests.cs b/tests/Eff.Tests/CustomEffectHandlerTests.cs index aa004e3..def677f 100644 --- a/tests/Eff.Tests/CustomEffectHandlerTests.cs +++ b/tests/Eff.Tests/CustomEffectHandlerTests.cs @@ -81,7 +81,7 @@ async Eff Test(int x) Assert.Equal(2, result); Assert.Single(handler.TraceLogs); - Assert.Single(handler.TraceLogs[0].Parameters); + Assert.Single(handler.TraceLogs[0].Parameters!); Assert.Equal("x", handler.TraceLogs[0].Parameters![0].name); Assert.Equal(1, (int)handler.TraceLogs[0].Parameters![0].value!); } @@ -101,10 +101,10 @@ async Eff Test(int x) Assert.Equal(2, result); Assert.Equal(2, handler.TraceLogs.Count); - Assert.Single(handler.TraceLogs[0].LocalVariables); + Assert.Single(handler.TraceLogs[0].LocalVariables!); Assert.Equal("y", handler.TraceLogs[0].LocalVariables![0].name); Assert.Equal(0, (int)handler.TraceLogs[0].LocalVariables![0].value!); - Assert.Single(handler.TraceLogs[1].LocalVariables); + Assert.Single(handler.TraceLogs[1].LocalVariables!); Assert.Equal("y", handler.TraceLogs[1].LocalVariables![0].name!); Assert.Equal(1, (int)handler.TraceLogs[1].LocalVariables![0].value!); } @@ -150,10 +150,10 @@ async Eff Test(int x) var result = await Test(1).Run(handler); Assert.Equal(2, result); - Assert.Single(handler.CaptureStateParameters); + Assert.Single(handler.CaptureStateParameters!); Assert.Equal("x", handler.CaptureStateParameters![0].name); Assert.Equal(1, (int)handler.CaptureStateParameters[0].value!); - Assert.Single(handler.CaptureStateLocalVariables); + Assert.Single(handler.CaptureStateLocalVariables!); Assert.Equal("y", handler.CaptureStateLocalVariables![0].name); Assert.Equal(1, (int)handler.CaptureStateLocalVariables[0].value!); } diff --git a/tests/Eff.Tests/Eff.Tests.csproj b/tests/Eff.Tests/Eff.Tests.csproj index f32c7c5..9bd63ec 100644 --- a/tests/Eff.Tests/Eff.Tests.csproj +++ b/tests/Eff.Tests/Eff.Tests.csproj @@ -2,16 +2,16 @@ Nessos.Effects.Tests - net6.0 + net8.0 $(NoWarn);CS1998 false - - - - + + + +