diff --git a/.editorconfig b/.editorconfig index 733ebd8..d49bcf8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -218,5 +218,5 @@ dotnet_naming_style.underscore_camel.capitalization = camel_case dotnet_analyzer_diagnostic.category-Globalization.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task -# In almost all cases in dotnet core this is unnecessary as there is syncronization context -dotnet_diagnostic.CA2007.severity = none \ No newline at end of file +# In almost all cases in dotnet core this is unnecessary as there is no synchronization context +dotnet_diagnostic.CA2007.severity = none diff --git a/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs b/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs index 5e95879..59e75e2 100644 --- a/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/AsMaybe_Test.cs @@ -55,7 +55,6 @@ public async Task AsMaybeTaskClass_Null_ReturnsNone() Assert.Equal(Maybe.None, res); } - [Fact] public async Task AsMaybeTaskClass_Value_ReturnsSome() { @@ -85,7 +84,5 @@ public async Task AsMaybeTaskNullable_Value_ReturnsSome() Assert.Equal(25, res.Value); } - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs b/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs index 0e0ae15..e8b35ff 100644 --- a/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/Expect_Test.cs @@ -25,7 +25,6 @@ public void ExpectMessage_WhiteSpaceMessage_Throws() Assert.Throws("message", () => underTest.Expect(" \t\r\n")); } - [Fact] public void ExpectMessage_DoesNotExist_ThrowsWithMessage() { @@ -85,8 +84,5 @@ public async Task ExpectTaskMessage_Value_ReturnsValue() var underTest = Task.FromResult(new Maybe(10)); Assert.Equal(10, await underTest.Expect(_message)); } - - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs b/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs index d4c99d1..fed9a38 100644 --- a/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/Flatten_Test.cs @@ -27,7 +27,6 @@ public void Flatten_InnerExistsAndIsValue_ReturnsValue() Assert.Equal(value, res.Value); } - [Fact] public void Flatten_InnerExistsAndIsError_ReturnsError() { diff --git a/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs b/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs index b7a7d25..fcb71fb 100644 --- a/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/OkOr_Test.cs @@ -25,7 +25,6 @@ public void OkOrFunc_None_ReturnsFuncResultAsError() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - [Fact] public void OkOrErrorValue_Value_ReturnsResultWithValue() { @@ -46,7 +45,6 @@ public void OkOrErrorValue_None_ReturnsErrorValue() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - [Fact] public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue() { @@ -56,7 +54,6 @@ public async Task OkOrErrorTaskFunc_Value_ReturnsResultWithValue() Assert.Equal("doot", result.Value); } - [Fact] public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue() { @@ -67,7 +64,6 @@ public async Task OkOrErrorTaskFunc_None_ReturnsResultWithValue() } - [Fact] public async Task OkOrErrorTaskValue_Value_ReturnsResultWithValue() { @@ -123,12 +119,9 @@ public async Task OkOrErrorTaskFunc_ResultMemberIsNone_ReturnsInternalResult() Assert.Equal(TestingEnum.BadThingsHappened, result.Error); } - public enum TestingEnum { BadThingsHappened } - - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs b/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs index 77d6b03..5c4fecd 100644 --- a/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/ResultMapping_Test.cs @@ -64,7 +64,6 @@ public async Task MapTaskResult_IsErrorAndFuncReturnsValue_ReturnsError() Assert.Equal(TestError.Sadness, res.Error); } - [Fact] public async Task MapTaskResult_IsSuccessAndFuncReturnsTask_ReturnsResultOfFunc() { @@ -133,7 +132,6 @@ public void MapErrorValue_IsErrorAndFuncReturnsValue_ReturnsResultOfFunc() Assert.Equal(OtherError.OtherSadness, res.Error); } - [Fact] public void MapErrorValue_IsSuccessAndFuncReturnsValue_ReturnsValue() { @@ -203,7 +201,6 @@ private static Result ConstructWith(T value) return new Result(value); } - private enum TestError { Sadness @@ -213,6 +210,5 @@ private enum OtherError { OtherSadness } - } } diff --git a/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs b/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs index 8515d9f..bbffc70 100644 --- a/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs +++ b/wimm.Secundatives.UnitTests/Extensions/UnwrapOr_Test.cs @@ -9,8 +9,17 @@ public class UnwrapOr_Test { private const string _valid = "doot"; private const string _default = "tood"; - private readonly Func _defaultFunc = () => { _set = true; return _default; }; - private readonly Func> _defaultAsyncFunc = async () => { _set = true; ; return await Task.FromResult(_default); }; + private readonly Func _defaultFunc = () => + { + _set = true; + return _default; + }; + private readonly Func> _defaultAsyncFunc = async () => + { + _set = true; + return await Task.FromResult(_default); + }; + private static bool _set = false; public UnwrapOr_Test() @@ -40,7 +49,6 @@ public void UnwrawpOrFunc_NoValue_ExecutesFunction() Assert.Equal(_default, underTest.UnwrapOr(_defaultFunc)); } - [Fact] public void UnwrapOr_NoValue_ReturnsDefaultParam() { diff --git a/wimm.Secundatives.UnitTests/Maybe_Test.cs b/wimm.Secundatives.UnitTests/Maybe_Test.cs index c64c0ce..cca64ae 100644 --- a/wimm.Secundatives.UnitTests/Maybe_Test.cs +++ b/wimm.Secundatives.UnitTests/Maybe_Test.cs @@ -6,7 +6,6 @@ namespace wimm.Secundatives.UnitTests public class Maybe_Test { - [Fact] public void Construct_ValueTypeDefault_EqualsNone() { @@ -349,7 +348,5 @@ public void GetHashCode_ValueMaybe_Throws() Assert.Throws(() => underTest.GetHashCode()); } - - } } diff --git a/wimm.Secundatives.UnitTests/Result_Test.cs b/wimm.Secundatives.UnitTests/Result_Test.cs index 82fc807..129c8c4 100644 --- a/wimm.Secundatives.UnitTests/Result_Test.cs +++ b/wimm.Secundatives.UnitTests/Result_Test.cs @@ -5,7 +5,7 @@ namespace wimm.Secundatives.UnitTests { public class Result_Test { - private readonly Error _err = new Error("BadDoot"); + private readonly Error _err = new("BadDoot"); [Fact] public void Error_ContainsValue_Throws() @@ -14,7 +14,6 @@ public void Error_ContainsValue_Throws() Assert.Throws(() => underTest.Error); } - [Fact] public void Value_ContainsError_Throws() { @@ -29,7 +28,6 @@ public void Error_ContainsError_ReturnsError() Assert.Equal(_err, underTest.Error); } - [Fact] public void Value_ContainsValue_ReturnsValue() { @@ -92,9 +90,7 @@ public void Ok_ContainsError_ReturnsNone() var underTest = ConstructErr(); Assert.False(underTest.Ok().Exists); } - - - private Result ConstructInt() + private static Result ConstructInt() { return 42; } @@ -103,6 +99,5 @@ private Result ConstructErr() { return _err; } - } } diff --git a/wimm.Secundatives.UnitTests/TestHelpers.cs b/wimm.Secundatives.UnitTests/TestHelpers.cs index 9d70dfe..5926372 100644 --- a/wimm.Secundatives.UnitTests/TestHelpers.cs +++ b/wimm.Secundatives.UnitTests/TestHelpers.cs @@ -8,7 +8,6 @@ public class TestHelpers { private static readonly List _stringControls = new() { "\t", "\r", "\n", " " }; - public static void AssertThrowsIfWhitespace(Action action) { foreach (var control in _stringControls) @@ -16,5 +15,13 @@ public static void AssertThrowsIfWhitespace(Action action) Assert.Throws(() => action(control)); } } + + public static void AssertThrowsIfWhitespace(Func action) + { + foreach (var control in _stringControls) + { + Assert.Throws(() => action(control)); + } + } } } diff --git a/wimm.Secundatives.UnitTests/Variant_Test.cs b/wimm.Secundatives.UnitTests/Variant_Test.cs index 9662069..52820e4 100644 --- a/wimm.Secundatives.UnitTests/Variant_Test.cs +++ b/wimm.Secundatives.UnitTests/Variant_Test.cs @@ -90,11 +90,8 @@ private static Variant ConstructInt() return new Variant(42); } - - class Base { } class Derived : Base { } class OtherDerived : Base { } - } } diff --git a/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj b/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj index e10f72c..845aa9c 100644 --- a/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj +++ b/wimm.Secundatives.UnitTests/wimm.Secundatives.UnitTests.csproj @@ -2,7 +2,6 @@ net6.0 - false diff --git a/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs b/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs index 2964779..4e17d83 100644 --- a/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs +++ b/wimm.Secundatives/ApplyFunctionsExtensions/ApplyFunctionsExtensions.cs @@ -28,8 +28,10 @@ public static class ApplyFunctionsExtensions /// public static TFunc Apply(this TArg target, Func fn, bool allowNull = false) { - if (target == null && !allowNull) throw new ArgumentNullException(nameof(target)); - if (fn == null) throw new ArgumentNullException(nameof(fn)); + if (target == null && !allowNull) + throw new ArgumentNullException(nameof(target)); + if (fn == null) + throw new ArgumentNullException(nameof(fn)); return fn(target); } @@ -53,8 +55,10 @@ public static TFunc Apply(this TArg target, Func fn, b /// public static bool In(this T target, IEnumerable enumerable, bool allowNull = false) { - if (target == null && !allowNull) throw new ArgumentNullException(nameof(target)); - if (enumerable == null) throw new ArgumentNullException(nameof(enumerable)); + if (target == null && !allowNull) + throw new ArgumentNullException(nameof(target)); + if (enumerable == null) + throw new ArgumentNullException(nameof(enumerable)); return enumerable.Contains(target, EqualityComparer.Default); } } diff --git a/wimm.Secundatives/Extensions/FlattenExtensions.cs b/wimm.Secundatives/Extensions/FlattenExtensions.cs index 0cad7e3..027cd5f 100644 --- a/wimm.Secundatives/Extensions/FlattenExtensions.cs +++ b/wimm.Secundatives/Extensions/FlattenExtensions.cs @@ -17,6 +17,8 @@ public static class FlattenExtensions /// The un-nested result of inspecting the outer result for error and returning it if it exists or the nested result itself otherwise /// public static Result Flatten(this Result, TErr> result) + where TValue : notnull + where TErr : notnull { return result.IsValue ? result.Value : result.Error; } @@ -31,6 +33,8 @@ public static Result Flatten(this Result public static async Task> Flatten(this Task, TErr>> res) + where TValue : notnull + where TErr : notnull { var result = await res; return result.IsValue ? result.Value : result.Error; diff --git a/wimm.Secundatives/Extensions/MaybeExtensions.cs b/wimm.Secundatives/Extensions/MaybeExtensions.cs index 96f1471..89687ce 100644 --- a/wimm.Secundatives/Extensions/MaybeExtensions.cs +++ b/wimm.Secundatives/Extensions/MaybeExtensions.cs @@ -20,7 +20,6 @@ public static class MaybeExtensions /// The held within if it exists. public static T Expect(this Maybe maybe) => maybe.Expect($"Expected value in {nameof(Maybe)}"); - /// Extension to indicate that a value missing from a is unrecoverable. /// Unwraps the if it exists or throws a /// with a custom message. @@ -54,7 +53,6 @@ public static async Task Expect(this Task> maybeTask, string mess return (await maybeTask).Expect(message); } - /// /// Helper function to apply in async contexts. Awaits the task containing the /// and then applies the function to it. @@ -68,7 +66,6 @@ public static async Task Expect(this Task> maybeTask) return (await maybeTask).Expect(); } - /// /// Unwraps the if possible and returns a provided default otherwise /// @@ -80,7 +77,6 @@ public static async Task Expect(this Task> maybeTask) /// public static T UnwrapOr(this Maybe maybe, T defaultValue) => maybe.Exists ? maybe.Value : defaultValue; - /// /// Unwraps the if possible and returns the results of a provided function otherwise /// @@ -103,7 +99,6 @@ public static async Task Expect(this Task> maybeTask) /// the result of awaiting the execution of public static async Task UnwrapOr(this Maybe maybe, Func> func) => maybe.Exists ? maybe.Value : await func(); - /// /// Unwraps the that results from the if possible and returns the results of awaiting the provided async function otherwise /// @@ -160,7 +155,6 @@ public static Maybe AsMaybe(this T? value) where T : struct return value.HasValue ? new Maybe(value.Value) : Maybe.None; } - /// /// Helper function that awaits a 's result and converts it into a /// @@ -175,7 +169,6 @@ public static async Task> AsMaybe(this Task value) where T : clas return (await value).AsMaybe(); } - /// /// Helper function that awaits a 's nullable result and converts it into a /// diff --git a/wimm.Secundatives/Extensions/OkOrExtensions.cs b/wimm.Secundatives/Extensions/OkOrExtensions.cs index 6af815a..839265e 100644 --- a/wimm.Secundatives/Extensions/OkOrExtensions.cs +++ b/wimm.Secundatives/Extensions/OkOrExtensions.cs @@ -23,6 +23,8 @@ public static class OkOrExtensions /// contains the result of executing /// public static Result OkOr(this Maybe value, Func func) + where T : notnull + where TError : notnull { if (value.Exists) return value.Value; @@ -30,7 +32,6 @@ public static Result OkOr(this Maybe value, Func /// Maps a into a by returning a default value if /// is None. In the case where contains a value returns a @@ -44,6 +45,8 @@ public static Result OkOr(this Maybe value, Func /// public static Result OkOr(this Maybe value, TError error) + where T : notnull + where TError : notnull { if (value.Exists) return value.Value; @@ -51,7 +54,6 @@ public static Result OkOr(this Maybe value, TError erro return error; } - /// /// Maps a containing a into a by returning a default value if /// is None. In the case where contains a value returns a @@ -65,12 +67,13 @@ public static Result OkOr(this Maybe value, TError erro /// contains /// public static async Task> OkOr(this Task> value, TError error) + where T : notnull + where TError : notnull { var v = await value; return v.OkOr(error); } - /// /// Maps a containing a into a by executing if /// is None. In the case where contains a value returns a @@ -84,13 +87,14 @@ public static async Task> OkOr(this Task> /// contains the result of executing /// public static async Task> OkOr(this Task> value, Func func) + where T : notnull + where TError : notnull { var v = await value; return v.OkOr(func); } - /// /// Collapsing mapping of a containing a that may hold a /// into a @@ -103,12 +107,13 @@ public static async Task> OkOr(this Task> /// A either contained by if it exists or created /// from if it is None public static async Task> OkOr(this Task>> value, TError error) + where T : notnull + where TError : notnull { var res = await value; return res.UnwrapOr(error); } - /// /// Collapsing mapping of a containing a that may hold a /// into a @@ -121,6 +126,8 @@ public static async Task> OkOr(this Task A either contained by if it exists or created /// from the results of calling if it is None public static async Task> OkOr(this Task>> value, Func func) + where T : notnull + where TError : notnull { var res = await value; return res.UnwrapOr(func()); diff --git a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs index f5d8647..7abedee 100644 --- a/wimm.Secundatives/Extensions/ResultMappingExtensions.cs +++ b/wimm.Secundatives/Extensions/ResultMappingExtensions.cs @@ -26,6 +26,9 @@ public static class ResultMappingExtensions /// if it exists. Otherwise returns a containing the contained within /// public static Result Map(this Result result, Func func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return func(result.Value); @@ -33,7 +36,6 @@ public static Result Map(this Result result, return result.Error; } - /// /// Transforms a into a by applying an async function if the mapped /// contains a value otherwise by constructing a new from the @@ -51,6 +53,9 @@ public static Result Map(this Result result, /// if it exists. Otherwise returns a containing the contained within /// public static async Task> Map(this Result result, Func> func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return await func(result.Value); @@ -73,12 +78,14 @@ public static async Task> Map(this Resultif it exists. Otherwise returns a containing the /// contained within public static async Task> Map(this Task> result, Func func) + where T : notnull + where U : notnull + where TError : notnull { var val = await result; return val.Map(func); } - /// /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -95,13 +102,15 @@ public static async Task> Map(this Task if it exists. Otherwise returns a containing the /// contained within public static async Task> Map(this Task> result, Func> func) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; return await res.Map(func); } - /// /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -119,6 +128,9 @@ public static async Task> Map(this Task containing the contained within /// public static async Task> Map(this Result result, Func>> func) + where T : notnull + where U : notnull + where TError : notnull { if (result.IsValue) return await func(result.Value); @@ -126,7 +138,6 @@ public static async Task> Map(this Result /// Asynchronously transforms a into a by applying an async function and collapsing /// the result if the mapped contains a value otherwise by constructing a new @@ -144,6 +155,9 @@ public static async Task> Map(this Result containing the contained within /// public static async Task> Map(this Task> result, Func>> func) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; if (res.IsValue) @@ -152,7 +166,6 @@ public static async Task> Map(this Task /// Transforms a into a by applying a function if the mapped /// contains a . Otherwise constructs a new @@ -169,6 +182,9 @@ public static async Task> Map(this Task of if it exists. Otherwise returns a /// containing the contained within public static Result MapError(this Result result, Func func) + where T : notnull + where TError : notnull + where UError : notnull { if (result.IsError) return func(result.Error); @@ -176,7 +192,6 @@ public static Result MapError(this Result /// Asynchronously transforms a into a by applying a function if the mapped /// contains a . Otherwise constructs a new @@ -193,6 +208,9 @@ public static Result MapError(this Result of if it exists. Otherwise returns a /// containing the contained within public static async Task> MapError(this Task> result, Func func) + where T : notnull + where TError : notnull + where UError : notnull { var val = await result; return val.MapError(func); @@ -214,6 +232,9 @@ public static async Task> MapError(this Tas /// name="result"/> or by calling on the error from /// public static U MapOr(this Result result, Func valueFunc, Func errorFunc) + where T : notnull + where U : notnull + where TError : notnull { return result.IsValue ? valueFunc(result.Value) : errorFunc(result.Error); } @@ -234,6 +255,9 @@ public static U MapOr(this Result result, Func va /// name="result"/> or by calling on the error from /// public static async Task MapOr(this Task> result, Func valueFunc, Func errorFunc) + where T : notnull + where U : notnull + where TError : notnull { var res = await result; return res.IsValue ? valueFunc(res.Value) : errorFunc(res.Error); diff --git a/wimm.Secundatives/Extensions/VariantExtensions.cs b/wimm.Secundatives/Extensions/VariantExtensions.cs index d8acad0..99cbd1c 100644 --- a/wimm.Secundatives/Extensions/VariantExtensions.cs +++ b/wimm.Secundatives/Extensions/VariantExtensions.cs @@ -24,8 +24,11 @@ public static class VariantExtensions /// contains a value of type /// public static W MapValue(this Variant variant, Func tMapping, Func uMapping) - => variant.Is() ? tMapping(variant.Get()) : uMapping(variant.Get()); + where T : notnull + where U : notnull + where W : notnull + => variant.Is() ? tMapping(variant.Get()) : uMapping(variant.Get()); /// /// Maps the contents of a variant to an action taking that type. Executes the function matching the type of the value @@ -42,6 +45,8 @@ public static W MapValue(this Variant variant, Func tMappin /// is /// public static void MapAction(this Variant variant, Action tAction, Action uAction) + where T : notnull + where U : notnull { if (variant.Is()) tAction(variant.Get()); diff --git a/wimm.Secundatives/Maybe.cs b/wimm.Secundatives/Maybe.cs index 20006e2..85495a7 100644 --- a/wimm.Secundatives/Maybe.cs +++ b/wimm.Secundatives/Maybe.cs @@ -11,7 +11,7 @@ public static class Maybe /// /// A static instance of None to reduce memory pressure and to facilitate simple conversions /// - public static readonly None None = new None(); + public static readonly None None = new(); } /// @@ -63,9 +63,9 @@ public Maybe(T value) public static bool operator !=(Maybe left, Maybe right) => !left.Equals(right); - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (!(obj is Maybe maybe)) + if (obj is not Maybe maybe) return false; return Equals(maybe); @@ -77,9 +77,9 @@ public bool Equals(Maybe other) && EqualityComparer.Default.Equals(_value, other._value); } - public static implicit operator Maybe(T value) => new Maybe(value); + public static implicit operator Maybe(T value) => new(value); - public static implicit operator Maybe(None _) => new Maybe(); + public static implicit operator Maybe(None _) => new(); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/wimm.Secundatives/NaturalRange.cs b/wimm.Secundatives/NaturalRange.cs index 8545f54..1494820 100644 --- a/wimm.Secundatives/NaturalRange.cs +++ b/wimm.Secundatives/NaturalRange.cs @@ -11,7 +11,6 @@ public class NaturalRange : IRange private const string _outOfRangeMessage = "Must be greater than or equal to zero."; private readonly Range _range; - /// /// /// @@ -41,8 +40,10 @@ public NaturalRange(int max) : this(0, max) { } /// public NaturalRange(int min, int max) { - if (min < 0) throw new ArgumentOutOfRangeException(nameof(min), _outOfRangeMessage); - if (max < 0) throw new ArgumentOutOfRangeException(nameof(max), _outOfRangeMessage); + if (min < 0) + throw new ArgumentOutOfRangeException(nameof(min), _outOfRangeMessage); + if (max < 0) + throw new ArgumentOutOfRangeException(nameof(max), _outOfRangeMessage); if (max < min) throw new ArgumentException( diff --git a/wimm.Secundatives/Range.cs b/wimm.Secundatives/Range.cs index 60e2e45..87600f8 100644 --- a/wimm.Secundatives/Range.cs +++ b/wimm.Secundatives/Range.cs @@ -26,8 +26,8 @@ public class Range : IRange where T : IComparable /// public Range(T min, T max) { - Min = Require(min, nameof(min)); - Max = Require(max, nameof(max)); + Min = Range.Require(min, nameof(min)); + Max = Range.Require(max, nameof(max)); if (max.CompareTo(min) < 0) throw new ArgumentException( @@ -41,14 +41,15 @@ public Range(T min, T max) /// true if is greater than and less than public bool Includes(T value) { - Require(value, nameof(value)); + Range.Require(value, nameof(value)); return !(Min.CompareTo(value) > 0 || Max.CompareTo(value) < 0); } - private T Require(T value, string name) + private static T Require(T value, string name) { - if (value == null) throw new ArgumentNullException(name); + if (value == null) + throw new ArgumentNullException(name); return value; } } diff --git a/wimm.Secundatives/Result.cs b/wimm.Secundatives/Result.cs index 78396a8..b110456 100644 --- a/wimm.Secundatives/Result.cs +++ b/wimm.Secundatives/Result.cs @@ -9,6 +9,8 @@ namespace wimm.Secundatives /// /// public class Result : Variant + where T : notnull + where TError : notnull { /// A value indicating whether the operation resulted in an error type public bool IsError => Is(); @@ -16,7 +18,6 @@ public class Result : Variant /// A value indicating if the operation successfully returned a value public bool IsValue => Is(); - /// Gets the value contained in the result. /// The result contains no value - operation failed public T Value => Get(); @@ -47,19 +48,18 @@ public Result(TError err) : base(err) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Result(T value) => new Result(value); - public static implicit operator Result(TError error) => new Result(error); + public static implicit operator Result(T value) => new(value); + public static implicit operator Result(TError error) => new(error); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } - - /// /// A basic Result class that handles operations with a possibility of failure that uses a special error class to /// report failure /// /// The type to be returned on success public class Result : Result + where T : notnull { /// @@ -78,9 +78,8 @@ public Result(Error err) : base(err) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Result(T value) => new Result(value); - public static implicit operator Result(Error error) => new Result(error); + public static implicit operator Result(T value) => new(value); + public static implicit operator Result(Error error) => new(error); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } - } diff --git a/wimm.Secundatives/Variant.cs b/wimm.Secundatives/Variant.cs index 67ebc94..4028fca 100644 --- a/wimm.Secundatives/Variant.cs +++ b/wimm.Secundatives/Variant.cs @@ -6,7 +6,9 @@ namespace wimm.Secundatives /// /// A typesafe union that contains either a or a /// - public class Variant + public class Variant + where T : notnull + where U : notnull { /// /// Ensures that and are not within the same @@ -41,7 +43,7 @@ public bool Is() { var wType = typeof(W); - if (!IsAssignableFromMemberType(wType)) + if (!Variant.IsAssignableFromMemberType(wType)) throw UnsupportedType(wType, new List { typeof(T), typeof(U) }); return _value is W; @@ -80,12 +82,11 @@ public Variant(U value) //CN(justification): These operators are trivial and their documentation would just be code bloat #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - public static implicit operator Variant(T val) => new Variant(val); - public static implicit operator Variant(U val) => new Variant(val); + public static implicit operator Variant(T val) => new(val); + public static implicit operator Variant(U val) => new(val); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - - private bool IsAssignableFromMemberType(Type type) + private static bool IsAssignableFromMemberType(Type type) { return typeof(U).IsAssignableFrom(type) || typeof(T).IsAssignableFrom(type); } @@ -101,10 +102,5 @@ private static NotSupportedException UnsupportedType(Type expected, IEnumerable< return new NotSupportedException( $"Variant was checked for type it cannot contain:\nRequested:{expected}\nAvailable: {string.Join("\n", available)}"); } - - - } - - } diff --git a/wimm.Secundatives/wimm.Secundatives.csproj b/wimm.Secundatives/wimm.Secundatives.csproj index 7616ed5..eabca77 100644 --- a/wimm.Secundatives/wimm.Secundatives.csproj +++ b/wimm.Secundatives/wimm.Secundatives.csproj @@ -11,16 +11,7 @@ https://github.com/wareismymind/secundatives git true + true + enable - - - true - 1591 - - - - - true - -