From 87adc5ea0b3ca4fa9729dcdd057e0658308eadb8 Mon Sep 17 00:00:00 2001 From: Daniel Wertheim Date: Mon, 18 Oct 2021 11:29:07 +0200 Subject: [PATCH] Next (#162) * Fixes #159, Only supports netstandard2.0 and netstandard2.1 * Fixes #161 * Changes EnsureOptions to be readonly * Change so that Ensure.That returns the Param * NuGet upgrades * Fixes benchmark * Docs --- README.md | 69 ++++- .../azure-pipelines-cd.yml | 7 +- .../azure-pipelines-ci.yml | 4 +- .../stage-build.yml | 18 +- .../stage-deploy.yml | 0 .../EnsureThat/Annotations/JetBrains.cs | 37 +-- .../Annotations/NotNullAttribute.cs | 2 +- src/projects/EnsureThat/Enforcers/AnyArg.cs | 12 + .../EnsureThat/Enforcers/CollectionArg.cs | 56 ++-- .../EnsureThat/Enforcers/EnumerableArg.cs | 14 +- src/projects/EnsureThat/Enforcers/TypeArg.cs | 10 - src/projects/EnsureThat/Ensure.cs | 3 +- .../EnsureThat/EnsureArg.Comparables.cs | 1 + src/projects/EnsureThat/EnsureOptions.cs | 44 +-- src/projects/EnsureThat/EnsureThat.csproj | 2 +- .../EnsureThat/EnsureThatAnyExtensions.cs | 31 ++- .../EnsureThatCollectionExtensions.cs | 250 +++++++++++++----- .../EnsureThatComparableDateTimeExtensions.cs | 58 ++-- .../EnsureThatComparableDecimalExtensions.cs | 58 ++-- .../EnsureThatComparableDoubleExtensions.cs | 58 ++-- .../EnsureThatComparableExtensions.cs | 114 ++++++-- .../EnsureThatComparableIntExtensions.cs | 58 ++-- .../EnsureThatComparableLongExtensions.cs | 58 ++-- .../EnsureThat/EnsureThatEnumExtensions.cs | 20 +- .../EnsureThat/EnsureThatStringExtensions.cs | 221 ++++++++++++---- .../EnsureThat/EnsureThatTypeExtensions.cs | 116 +++++--- .../EnsureThatValueTypeExtensions.cs | 42 ++- src/projects/EnsureThat/IExceptionFactory.cs | 2 +- .../Internals/DefaultExceptionFactory.cs | 10 +- src/projects/EnsureThat/OptsFn.cs | 4 +- src/projects/EnsureThat/Param.cs | 2 +- src/tests/Benchmarks/Benchmarks.csproj | 2 +- src/tests/Benchmarks/Program.cs | 10 +- .../UnitTests/DefaultExceptionFactoryTests.cs | 19 +- src/tests/UnitTests/OptsTests.cs | 41 +-- src/tests/UnitTests/UnitTests.csproj | 6 +- 36 files changed, 1000 insertions(+), 459 deletions(-) rename azure-pipelines-cd.yml => azure-devops/azure-pipelines-cd.yml (56%) rename azure-pipelines-ci.yml => azure-devops/azure-pipelines-ci.yml (85%) rename {azure-templates => azure-devops}/stage-build.yml (76%) rename {azure-templates => azure-devops}/stage-deploy.yml (100%) diff --git a/README.md b/README.md index 9cb0f47c..b991cb30 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,88 @@ # Ensure.That Ensure.That is a simple guard clause argument validation lib, that helps you with validation of your arguments. -It's developed for .NET 4.5.1 as well as .NET Standard 1.1, 2.0, and 2.1 available via [NuGet](https://www.nuget.org/packages/ensure.that/). +It's developed for .NET Standard 2.0 and 2.1 available via [NuGet](https://www.nuget.org/packages/ensure.that/). [![Build Status](https://dev.azure.com/daniel-wertheim/os/_apis/build/status/Ensure.That-CI?branchName=master)](https://dev.azure.com/daniel-wertheim/os/_build/latest?definitionId=1&branchName=master) [![NuGet](https://img.shields.io/nuget/v/ensure.that.svg)](http://nuget.org/packages/ensure.that) ## Using extension methods -This was supposed to be removed but after some wishes from the community it has been kept it with some slight changes. - -If you are worried that the constructed `public struct Param {}` created for the argument being validated will hurt your performance you can use any of the other constructs e.g. contextual `Ensure.String` or `EnsureArg`. ```csharp Ensure.That(myString).IsNotNullOrWhiteSpace(); Ensure.That(myString, nameof(myArg)).IsNotNullOrWhiteSpace(); -Ensure.That(myString, nameof(myArg), opts => opts.WithMessage("Foo")).IsNotNullOrWhiteSpace(); +Ensure.That(myString, nameof(myArg), (in EnsureOptions opts) => opts.WithMessage("Foo")).IsNotNullOrWhiteSpace(); +``` + +Chainable: + +```csharp +Ensure +.That(myString) +.IsNotNullOrWhiteSpace() +.IsGuid(); ``` +Easily extendable: + +```csharp +public static class StringArgExtensions +{ + public static StringParam IsNotFishy(this StringParam param) + => param.Value != "fishy" + ? param + : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", param.Name); +} + +Ensure.That(myString, nameof(myString)).IsNotFishy(); +``` + +**NOTE:** If you are worried that the constructed `public readonly struct Param {}` created for the argument being validated will hurt your performance you can use any of the other constructs e.g. contextual `Ensure.String` or `EnsureArg` (see below for samples). + ## Using contextual validation -This flavour was introduced in the `v7.0.0` release. +Introduced in the `v7.0.0` release. ```csharp Ensure.String.IsNotNullOrWhiteSpace(myString); Ensure.String.IsNotNullOrWhiteSpace(myString, nameof(myArg)); -Ensure.String.IsNotNullOrWhiteSpace(myString, nameof(myArg), opts => opts.WithMessage("Foo")); +Ensure.String.IsNotNullOrWhiteSpace(myString, nameof(myArg), (in EnsureOptions opts) => opts.WithMessage("Foo")); ``` + +Easily extendable: + +```csharp +public static class StringArgExtensions +{ + public static string IsNotFishy(this StringArg _, string value, string paramName = null) + => value != "fishy" + ? value + : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", paramName); +} + +Ensure.String.IsNotFishy(myString, nameof(myString)); +``` + ### Using static simple methods -The `EnsureArg` flavour was added in the `v5.0.0` release. +Introduced in the `v5.0.0` release. ```csharp EnsureArg.IsNotNullOrWhiteSpace(myString); EnsureArg.IsNotNullOrWhiteSpace(myString, nameof(myArg)); -EnsureArg.IsNotNullOrWhiteSpace(myString, nameof(myArg), opts => opts.WithMessage("Foo")); +EnsureArg.IsNotNullOrWhiteSpace(myString, nameof(myArg), (in EnsureOptions opts) => opts.WithMessage("Foo")); +``` + +Easily extendable: + +```csharp +public static partial class EnsureArg +{ + public static string IsNotFishy(string value, string paramName = null) + => value != "fishy" + ? value + : throw Ensure.ExceptionFactory.ArgumentException("Something is fishy!", paramName); +} + +EnsureArg.IsNotFishy(myString, nameof(myString)); ``` ## Samples diff --git a/azure-pipelines-cd.yml b/azure-devops/azure-pipelines-cd.yml similarity index 56% rename from azure-pipelines-cd.yml rename to azure-devops/azure-pipelines-cd.yml index cab7eed4..211e1eb1 100644 --- a/azure-pipelines-cd.yml +++ b/azure-devops/azure-pipelines-cd.yml @@ -2,7 +2,6 @@ name: $(SemVer) variables: BuildConfiguration: Release - BuildRev: $[counter(format('{0:yyyyMMdd}', pipeline.startTime), 1)] SemVer: $[ variables['Build.SourceBranchName'] ] CommitId: $(Build.SourceVersion) @@ -15,8 +14,8 @@ trigger: pr: none pool: - vmImage: windows-2019 + vmImage: ubuntu-latest stages: -- template: azure-templates/stage-build.yml -- template: azure-templates/stage-deploy.yml \ No newline at end of file +- template: stage-build.yml +- template: stage-deploy.yml diff --git a/azure-pipelines-ci.yml b/azure-devops/azure-pipelines-ci.yml similarity index 85% rename from azure-pipelines-ci.yml rename to azure-devops/azure-pipelines-ci.yml index b5d06bd6..dd691914 100644 --- a/azure-pipelines-ci.yml +++ b/azure-devops/azure-pipelines-ci.yml @@ -19,7 +19,7 @@ pr: - master pool: - vmImage: windows-2019 + vmImage: ubuntu-latest stages: -- template: azure-templates/stage-build.yml \ No newline at end of file +- template: stage-build.yml diff --git a/azure-templates/stage-build.yml b/azure-devops/stage-build.yml similarity index 76% rename from azure-templates/stage-build.yml rename to azure-devops/stage-build.yml index ce159809..46cd6aaf 100644 --- a/azure-templates/stage-build.yml +++ b/azure-devops/stage-build.yml @@ -13,19 +13,11 @@ stages: projects: 'src/*.sln' arguments: '-c $(BuildConfiguration) --no-incremental --nologo -p:TreatWarningsAsErrors=true -p:Version=$(SemVer) -p:InformationalVersion=$(CommitId)' - - task: DotNetCoreCLI@2 - displayName: 'UnitTests .Net4.5.2' - inputs: - command: test - projects: 'src/Tests/**/UnitTests.csproj' - arguments: '-c $(BuildConfiguration) -f net452 --no-build' - testRunTitle: 'UnitTests .Net4.5.2' - - task: DotNetCoreCLI@2 displayName: 'UnitTests .NetCoreApp3.1' inputs: command: test - projects: 'src/Tests/**/UnitTests.csproj' + projects: 'src/**/UnitTests.csproj' arguments: '-c $(BuildConfiguration) -f netcoreapp3.1 --no-build' testRunTitle: 'UnitTests .NetCoreApp3.1' @@ -33,10 +25,10 @@ stages: displayName: 'UnitTests .Net5' inputs: command: test - projects: 'src/Tests/**/UnitTests.csproj' + projects: 'src/**/UnitTests.csproj' arguments: '-c $(BuildConfiguration) -f net5.0 --no-build' testRunTitle: 'UnitTests .Net5' - + - task: DotNetCoreCLI@2 displayName: 'Pack Nupkg' inputs: @@ -44,9 +36,9 @@ stages: custom: pack projects: 'src/*.sln' arguments: '-c $(BuildConfiguration) --no-build -o $(Build.ArtifactStagingDirectory) -p:Version=$(SemVer) -p:InformationalVersion=$(CommitId)' - + - task: PublishPipelineArtifact@1 displayName: 'Publish Artifacts' inputs: path: '$(Build.ArtifactStagingDirectory)' - artifact: Artifacts \ No newline at end of file + artifact: Artifacts diff --git a/azure-templates/stage-deploy.yml b/azure-devops/stage-deploy.yml similarity index 100% rename from azure-templates/stage-deploy.yml rename to azure-devops/stage-deploy.yml diff --git a/src/projects/EnsureThat/Annotations/JetBrains.cs b/src/projects/EnsureThat/Annotations/JetBrains.cs index 92ecbbd4..ff049962 100644 --- a/src/projects/EnsureThat/Annotations/JetBrains.cs +++ b/src/projects/EnsureThat/Annotations/JetBrains.cs @@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; +using System.Diagnostics.CodeAnalysis; #pragma warning disable 1591 // ReSharper disable UnusedMember.Global @@ -44,40 +45,6 @@ internal sealed class RegexPatternAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter)] internal sealed class NoEnumerationAttribute : Attribute { } - /// - /// Indicates that the value of the marked element could never be null. - /// - /// - /// [NotNull] object Foo() { - /// return null; // Warning: Possible 'null' assignment - /// } - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - internal sealed class NotNullAttribute : Attribute { } - - /// - /// Indicates that a method does not make any observable state changes. - /// The same as System.Diagnostics.Contracts.PureAttribute. - /// - /// - /// [Pure] int Multiply(int x, int y) => x * y; - /// - /// void M() { - /// Multiply(123, 42); // Waring: Return value of pure method is not used - /// } - /// - /// - /// System.Diagnostics.Contracts.PureAttribute is not available for NETSTANDARD1_1. - /// For consistency, using this version of the attribute for all profiles rather than - /// just NETSTANDARD1_1. - /// - [AttributeUsage(AttributeTargets.Method)] - internal sealed class PureAttribute : Attribute { } - - /// /// Indicates that the function argument should be string literal and match one /// of the parameters of the caller function. For example, ReSharper annotates @@ -129,7 +96,7 @@ internal sealed class InvokerParameterNameAttribute : Attribute { } /// // A method that returns null if the parameter is null, /// // and not null if the parameter is not null /// [ContractAnnotation("null => null; notnull => notnull")] - /// public object Transform(object data) + /// public object Transform(object data) /// /// /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] diff --git a/src/projects/EnsureThat/Annotations/NotNullAttribute.cs b/src/projects/EnsureThat/Annotations/NotNullAttribute.cs index b0c97340..2caaf622 100644 --- a/src/projects/EnsureThat/Annotations/NotNullAttribute.cs +++ b/src/projects/EnsureThat/Annotations/NotNullAttribute.cs @@ -5,7 +5,7 @@ namespace System.Diagnostics.CodeAnalysis { /// /// This is JUST so we can avoid having #if regions in each usage site. - /// + /// /// For non-supported frameworks, it may be ignored by CodeAnalysis, but allows the usage /// sites to avoid all having /// diff --git a/src/projects/EnsureThat/Enforcers/AnyArg.cs b/src/projects/EnsureThat/Enforcers/AnyArg.cs index 997c134f..d99db450 100644 --- a/src/projects/EnsureThat/Enforcers/AnyArg.cs +++ b/src/projects/EnsureThat/Enforcers/AnyArg.cs @@ -31,6 +31,18 @@ public T HasValue([NoEnumeration, ValidatedNotNull, NotNull] T value, [Invoke return value; } + /// + /// Ensures value is not null. + /// Supports both and reference types. + /// If you know you are dealing with a certain type, e.g struct use preferred + /// overload instead as it is more performant. + /// + /// + /// + /// + /// + /// + /// If you know you are dealing with e.g. a struct, the overload is more performant. [return: NotNull] [ContractAnnotation("value:null => halt")] public T IsNotNull([NoEnumeration, ValidatedNotNull, NotNull] T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class diff --git a/src/projects/EnsureThat/Enforcers/CollectionArg.cs b/src/projects/EnsureThat/Enforcers/CollectionArg.cs index a76b3bb7..8ea68d62 100644 --- a/src/projects/EnsureThat/Enforcers/CollectionArg.cs +++ b/src/projects/EnsureThat/Enforcers/CollectionArg.cs @@ -16,7 +16,7 @@ public sealed class CollectionArg [ContractAnnotation("value:null => halt")] public T HasItems([ValidatedNotNull, NotNull]T value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -31,7 +31,7 @@ public T HasItems([ValidatedNotNull, NotNull]T value, [InvokerParameterName] [ContractAnnotation("value:null => halt")] public ICollection HasItems([ValidatedNotNull, NotNull]ICollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -46,7 +46,7 @@ public ICollection HasItems([ValidatedNotNull, NotNull]ICollection valu [ContractAnnotation("value:null => halt")] public IReadOnlyCollection HasItems([ValidatedNotNull, NotNull]IReadOnlyCollection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -61,7 +61,7 @@ public IReadOnlyCollection HasItems([ValidatedNotNull, NotNull]IReadOnlyCo [ContractAnnotation("value:null => halt")] public IReadOnlyList HasItems([ValidatedNotNull, NotNull]IReadOnlyList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -76,7 +76,7 @@ public IReadOnlyList HasItems([ValidatedNotNull, NotNull]IReadOnlyList [ContractAnnotation("value:null => halt")] public ISet HasItems([ValidatedNotNull, NotNull]ISet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -91,7 +91,7 @@ public ISet HasItems([ValidatedNotNull, NotNull]ISet value, [InvokerPar [ContractAnnotation("value:null => halt")] public T[] HasItems([ValidatedNotNull, NotNull]T[] value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Length == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -106,7 +106,7 @@ public T[] HasItems([ValidatedNotNull, NotNull]T[] value, [InvokerParameterNa [ContractAnnotation("value:null => halt")] public IList HasItems([ValidatedNotNull, NotNull] IList value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -121,7 +121,7 @@ public IList HasItems([ValidatedNotNull, NotNull] IList value, [Invoker [ContractAnnotation("value:null => halt")] public IDictionary HasItems([ValidatedNotNull, NotNull]IDictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -136,7 +136,7 @@ public IDictionary HasItems([ValidatedNotNull, NotNu [ContractAnnotation("value:null => halt")] public Collection HasItems([ValidatedNotNull, NotNull] Collection value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -151,7 +151,7 @@ public Collection HasItems([ValidatedNotNull, NotNull] Collection value [ContractAnnotation("value:null => halt")] public List HasItems([ValidatedNotNull, NotNull] List value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -166,7 +166,7 @@ public List HasItems([ValidatedNotNull, NotNull] List value, [InvokerPa [ContractAnnotation("value:null => halt")] public HashSet HasItems([ValidatedNotNull, NotNull] HashSet value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -181,7 +181,7 @@ public HashSet HasItems([ValidatedNotNull, NotNull] HashSet value, [Inv [ContractAnnotation("value:null => halt")] public Dictionary HasItems([ValidatedNotNull, NotNull]Dictionary value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count == 0) throw Ensure.ExceptionFactory.ArgumentException( @@ -196,7 +196,7 @@ public Dictionary HasItems([ValidatedNotNull, NotNul [ContractAnnotation("value:null => halt")] public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Length != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -211,13 +211,9 @@ public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, int expected, [Invoke [ContractAnnotation("value:null => halt")] public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); -#if NET452 - if (value.LongLength != expected) -#else if (value.Length != expected) -#endif throw Ensure.ExceptionFactory.ArgumentException( string.Format(ExceptionMessages.Collections_SizeIs_Failed, expected, value.Length), paramName, @@ -230,7 +226,7 @@ public T[] SizeIs([ValidatedNotNull, NotNull]T[] value, long expected, [Invok [ContractAnnotation("value:null => halt")] public T SizeIs([ValidatedNotNull, NotNull]T value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -245,7 +241,7 @@ public T SizeIs([ValidatedNotNull, NotNull]T value, int expected, [InvokerPar [ContractAnnotation("value:null => halt")] public T SizeIs([ValidatedNotNull, NotNull]T value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) where T : class, ICollection { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -260,7 +256,7 @@ public T SizeIs([ValidatedNotNull, NotNull]T value, long expected, [InvokerPa [ContractAnnotation("value:null => halt")] public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -275,7 +271,7 @@ public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, [ContractAnnotation("value:null => halt")] public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -290,7 +286,7 @@ public ICollection SizeIs([ValidatedNotNull, NotNull]ICollection value, [ContractAnnotation("value:null => halt")] public IList SizeIs([ValidatedNotNull, NotNull] IList value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -305,7 +301,7 @@ public IList SizeIs([ValidatedNotNull, NotNull] IList value, int expect [ContractAnnotation("value:null => halt")] public IList SizeIs([ValidatedNotNull, NotNull]IList value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -320,7 +316,7 @@ public IList SizeIs([ValidatedNotNull, NotNull]IList value, long expect [ContractAnnotation("value:null => halt")] public IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -335,7 +331,7 @@ public IDictionary SizeIs([ValidatedNotNull, NotNull [ContractAnnotation("value:null => halt")] public IDictionary SizeIs([ValidatedNotNull, NotNull]IDictionary value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (value.Count != expected) throw Ensure.ExceptionFactory.ArgumentException( @@ -350,7 +346,7 @@ public IDictionary SizeIs([ValidatedNotNull, NotNull [ContractAnnotation("value:null => halt")] public IDictionary ContainsKey([ValidatedNotNull, NotNull]IDictionary value, TKey expectedKey, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.ContainsKey(expectedKey)) throw Ensure.ExceptionFactory.ArgumentException( @@ -365,7 +361,7 @@ public IDictionary ContainsKey([ValidatedNotNull, No [ContractAnnotation("value:null => halt")] public IList HasAny([ValidatedNotNull, NotNull]IList value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.Any(predicate)) throw Ensure.ExceptionFactory.ArgumentException( @@ -380,7 +376,7 @@ public IList HasAny([ValidatedNotNull, NotNull]IList value, Func halt")] public ICollection HasAny([ValidatedNotNull, NotNull]ICollection value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.Any(predicate)) throw Ensure.ExceptionFactory.ArgumentException( @@ -395,7 +391,7 @@ public ICollection HasAny([ValidatedNotNull, NotNull]ICollection value, [ContractAnnotation("value:null => halt")] public T[] HasAny([ValidatedNotNull, NotNull]T[] value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.Any(predicate)) throw Ensure.ExceptionFactory.ArgumentException( diff --git a/src/projects/EnsureThat/Enforcers/EnumerableArg.cs b/src/projects/EnsureThat/Enforcers/EnumerableArg.cs index 39568634..cad11d47 100644 --- a/src/projects/EnsureThat/Enforcers/EnumerableArg.cs +++ b/src/projects/EnsureThat/Enforcers/EnumerableArg.cs @@ -20,7 +20,7 @@ public sealed class EnumerableArg [ContractAnnotation("value:null => halt")] public IEnumerable HasItems([ValidatedNotNull, InstantHandle]IEnumerable value, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.Any()) throw Ensure.ExceptionFactory.ArgumentException( @@ -35,7 +35,7 @@ public IEnumerable HasItems([ValidatedNotNull, InstantHandle]IEnumerable halt")] public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable value, int expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); var count = value.Count(); @@ -52,17 +52,11 @@ public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable [ContractAnnotation("value:null => halt")] public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable value, long expected, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); -#if NETSTANDARD1_1 var count = value.LongCount(); if (count != expected) -#else - var count = value.LongCount(); - - if (count != expected) -#endif throw Ensure.ExceptionFactory.ArgumentException( string.Format(ExceptionMessages.Collections_SizeIs_Failed, expected, count), paramName, @@ -75,7 +69,7 @@ public IEnumerable SizeIs([ValidatedNotNull, InstantHandle]IEnumerable [ContractAnnotation("value:null => halt")] public IEnumerable HasAny([ValidatedNotNull, InstantHandle]IEnumerable value, Func predicate, [InvokerParameterName] string paramName = null, OptsFn optsFn = null) { - Ensure.Any.IsNotNull(value, paramName); + Ensure.Any.IsNotNull(value, paramName, optsFn); if (!value.Any(predicate)) throw Ensure.ExceptionFactory.ArgumentException( diff --git a/src/projects/EnsureThat/Enforcers/TypeArg.cs b/src/projects/EnsureThat/Enforcers/TypeArg.cs index fd54aecf..479ca3a5 100644 --- a/src/projects/EnsureThat/Enforcers/TypeArg.cs +++ b/src/projects/EnsureThat/Enforcers/TypeArg.cs @@ -180,12 +180,7 @@ public Type IsAssignableToType([ValidatedNotNull, NotNull]Type param, Type expec Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(expectedType, nameof(expectedType)); -#if NETSTANDARD1_1 - // According to: https://devblogs.microsoft.com/dotnet/porting-to-net-core/. - if (!expectedType.GetTypeInfo().IsAssignableFrom(param.GetTypeInfo())) -#else if (!expectedType.IsAssignableFrom(param)) -#endif throw Ensure.ExceptionFactory.ArgumentException( string.Format(ExceptionMessages.Types_IsAssignableToType_Failed, expectedType.FullName, param.FullName), paramName, @@ -212,12 +207,7 @@ public Type IsNotAssignableToType([ValidatedNotNull, NotNull]Type param, Type no Ensure.Any.IsNotNull(param, paramName, optsFn); Ensure.Any.IsNotNull(nonExpectedType, nameof(nonExpectedType)); -#if NETSTANDARD1_1 - // According to: https://devblogs.microsoft.com/dotnet/porting-to-net-core/. - if (nonExpectedType.GetTypeInfo().IsAssignableFrom(param.GetTypeInfo())) -#else if (nonExpectedType.IsAssignableFrom(param)) -#endif throw Ensure.ExceptionFactory.ArgumentException( string.Format(ExceptionMessages.Types_IsNotAssignableToType_Failed, nonExpectedType.FullName), paramName, diff --git a/src/projects/EnsureThat/Ensure.cs b/src/projects/EnsureThat/Ensure.cs index e4b7347a..519ec608 100644 --- a/src/projects/EnsureThat/Ensure.cs +++ b/src/projects/EnsureThat/Ensure.cs @@ -1,6 +1,7 @@ using System; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; using EnsureThat.Enforcers; -using EnsureThat.Internals; using JetBrains.Annotations; namespace EnsureThat diff --git a/src/projects/EnsureThat/EnsureArg.Comparables.cs b/src/projects/EnsureThat/EnsureArg.Comparables.cs index 4cd2c703..96fad19e 100644 --- a/src/projects/EnsureThat/EnsureArg.Comparables.cs +++ b/src/projects/EnsureThat/EnsureArg.Comparables.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; namespace EnsureThat diff --git a/src/projects/EnsureThat/EnsureOptions.cs b/src/projects/EnsureThat/EnsureOptions.cs index 61e74a93..595de015 100644 --- a/src/projects/EnsureThat/EnsureOptions.cs +++ b/src/projects/EnsureThat/EnsureOptions.cs @@ -4,15 +4,17 @@ namespace EnsureThat { public delegate Exception CustomExceptionFactory(string message, string paramName); - public struct EnsureOptions + public readonly struct EnsureOptions { + public static readonly EnsureOptions Default = new(); + /// /// If defined, this factory will be used to produce the exception that /// will be thrown instead of the standard exceptions for the particular /// ensure method. /// Assign using . /// - public CustomExceptionFactory CustomExceptionFactory { get; private set; } + public CustomExceptionFactory CustomExceptionFactory { get; } /// /// If defined, and no has been defined, @@ -20,7 +22,7 @@ public struct EnsureOptions /// particular ensure method. /// Assign using . /// - public Exception CustomException { get; private set; } + public Exception CustomException { get; } /// /// If defined, and neither @@ -29,27 +31,31 @@ public struct EnsureOptions /// particular ensure method. /// Assign using . /// - public string CustomMessage { get; private set; } + public string CustomMessage { get; } - public EnsureOptions WithExceptionFactory(CustomExceptionFactory factory) + private EnsureOptions( + CustomExceptionFactory customExceptionFactory, + Exception customException, + string customMessage) { - CustomExceptionFactory = factory; - - return this; + CustomExceptionFactory = customExceptionFactory; + CustomException = customException; + CustomMessage = customMessage; } - public EnsureOptions WithException(Exception ex) - { - CustomException = ex; + public EnsureOptions WithExceptionFactory(CustomExceptionFactory factory) => + new(factory, + CustomException, + CustomMessage); - return this; - } + public EnsureOptions WithException(Exception ex)=> + new(CustomExceptionFactory, + ex, + CustomMessage); - public EnsureOptions WithMessage(string message) - { - CustomMessage = message; - - return this; - } + public EnsureOptions WithMessage(string message)=> + new(CustomExceptionFactory, + CustomException, + message); } } diff --git a/src/projects/EnsureThat/EnsureThat.csproj b/src/projects/EnsureThat/EnsureThat.csproj index c22dfdce..f6dcad69 100644 --- a/src/projects/EnsureThat/EnsureThat.csproj +++ b/src/projects/EnsureThat/EnsureThat.csproj @@ -1,7 +1,7 @@ - net4.5.1;netstandard1.1;netstandard2.0;netstandard2.1 + netstandard2.0;netstandard2.1 Ensure.That Ensure.That ensure-that ensure that argument validation guard clause contracts diff --git a/src/projects/EnsureThat/EnsureThatAnyExtensions.cs b/src/projects/EnsureThat/EnsureThatAnyExtensions.cs index 58c33cdb..38eecc0d 100644 --- a/src/projects/EnsureThat/EnsureThatAnyExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatAnyExtensions.cs @@ -7,16 +7,33 @@ public static class EnsureThatAnyExtensions /// /// Ensures value is not null. /// Supports both and reference types. - /// If you know you are dealing with a certain type, e.g struct use preferred + /// If you know you are dealing with a certain type, e.g struct use preferred /// overload instead as it is more performant. /// /// /// - /// If you know you are dealing with e.g. a struct, the overload is more performant. - public static void HasValue(this in Param param) - => Ensure.Any.HasValue(param.Value, param.Name, param.OptsFn); + /// If you know you are dealing with e.g. a struct, the overload is more performant. + public static Param HasValue(this in Param param) + { + Ensure.Any.HasValue(param.Value, param.Name, param.OptsFn); - public static void IsNotNull(this in Param param) where T : class - => Ensure.Any.IsNotNull(param.Value, param.Name, param.OptsFn); + return param; + } + + /// + /// Ensures value is not null. + /// Supports both and reference types. + /// If you know you are dealing with a certain type, e.g struct use preferred + /// overload instead as it is more performant. + /// + /// + /// + /// If you know you are dealing with e.g. a struct, the overload is more performant. + public static Param IsNotNull(this in Param param) where T : class + { + Ensure.Any.IsNotNull(param.Value, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatCollectionExtensions.cs b/src/projects/EnsureThat/EnsureThatCollectionExtensions.cs index 280f3f21..234c6137 100644 --- a/src/projects/EnsureThat/EnsureThatCollectionExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatCollectionExtensions.cs @@ -7,97 +7,221 @@ namespace EnsureThat { public static class EnsureThatCollectionExtensions { - public static void HasItems(this in Param param) where T : class, ICollection - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param HasItems(this in Param param) where T : class, ICollection + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param HasItems(this in Param param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void HasItems(this in Param> param) - => Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); + return param; + } - public static void SizeIs(this in Param param, int expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void SizeIs(this in Param param, long expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void SizeIs(this in Param param, int expected) where T : class, ICollection - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void SizeIs(this in Param param, long expected) where T : class, ICollection - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void SizeIs(this in Param> param, int expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void SizeIs(this in Param> param, long expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void SizeIs(this in Param> param, int expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void SizeIs(this in Param> param, long expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void SizeIs(this in Param> param, int expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void SizeIs(this in Param> param, long expected) - => Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void ContainsKey(this in Param> param, TKey key) - => Ensure.Collection.ContainsKey(param.Value, key, param.Name, param.OptsFn); + public static Param> HasItems(this in Param> param) + { + Ensure.Collection.HasItems(param.Value, param.Name, param.OptsFn); - public static void ContainsKey(this in Param> param, TKey key) - => Ensure.Collection.ContainsKey(param.Value, key, param.Name, param.OptsFn); + return param; + } - public static void HasAny(this in Param> param, Func predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + public static Param SizeIs(this in Param param, int expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); - public static void HasAny(this in Param> param, Func predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + return param; + } - public static void HasAny(this in Param> param, Func predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + public static Param SizeIs(this in Param param, long expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); - public static void HasAny(this in Param> param, Func predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + return param; + } - public static void HasAny(this in Param> param, Func, bool> predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + public static Param SizeIs(this in Param param, int expected) where T : class, ICollection + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); - public static void HasAny(this in Param> param, Func, bool> predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + return param; + } - public static void HasAny(this in Param param, Func predicate) - => Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + public static Param SizeIs(this in Param param, long expected) where T : class, ICollection + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, int expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, long expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, int expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, long expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, int expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> SizeIs(this in Param> param, long expected) + { + Ensure.Collection.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static Param> ContainsKey(this in Param> param, TKey key) + { + Ensure.Collection.ContainsKey(param.Value, key, param.Name, param.OptsFn); + + return param; + } + + public static Param> ContainsKey(this in Param> param, TKey key) + { + Ensure.Collection.ContainsKey(param.Value, key, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func, bool> predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param> HasAny(this in Param> param, Func, bool> predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } + + public static Param HasAny(this in Param param, Func predicate) + { + Ensure.Collection.HasAny(param.Value, predicate, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableDateTimeExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableDateTimeExtensions.cs index 8cce283c..adc03477 100644 --- a/src/projects/EnsureThat/EnsureThatComparableDateTimeExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableDateTimeExtensions.cs @@ -4,25 +4,53 @@ namespace EnsureThat { public static class EnsureThatComparableDateTimeExtensions { - public static void Is(this in Param param, DateTime expected) - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, DateTime expected) + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void IsNot(this in Param param, DateTime expected) - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, DateTime limit) - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, DateTime expected) + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLte(this in Param param, DateTime limit) - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, DateTime limit) - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, DateTime limit) + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGte(this in Param param, DateTime limit) - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, DateTime min, DateTime max) - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, DateTime limit) + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, DateTime limit) + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, DateTime limit) + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, DateTime min, DateTime max) + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableDecimalExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableDecimalExtensions.cs index 47e34c3e..8255e1e6 100644 --- a/src/projects/EnsureThat/EnsureThatComparableDecimalExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableDecimalExtensions.cs @@ -2,25 +2,53 @@ { public static class EnsureThatComparableDecimalExtensions { - public static void Is(this in Param param, decimal expected) - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, decimal expected) + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void IsNot(this in Param param, decimal expected) - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, decimal limit) - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, decimal expected) + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLte(this in Param param, decimal limit) - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, decimal limit) - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, decimal limit) + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGte(this in Param param, decimal limit) - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, decimal min, decimal max) - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, decimal limit) + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, decimal limit) + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, decimal limit) + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, decimal min, decimal max) + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableDoubleExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableDoubleExtensions.cs index 354152b0..ed4d4271 100644 --- a/src/projects/EnsureThat/EnsureThatComparableDoubleExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableDoubleExtensions.cs @@ -2,25 +2,53 @@ { public static class EnsureThatComparableDoubleExtensions { - public static void Is(this in Param param, double expected) - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, double expected) + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void IsNot(this in Param param, double expected) - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, double limit) - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, double expected) + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLte(this in Param param, double limit) - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, double limit) - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, double limit) + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGte(this in Param param, double limit) - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, double min, double max) - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, double limit) + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, double limit) + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, double limit) + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, double min, double max) + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableExtensions.cs index 2ef6c1cf..9cd520fa 100644 --- a/src/projects/EnsureThat/EnsureThatComparableExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableExtensions.cs @@ -5,46 +5,102 @@ namespace EnsureThat { public static class EnsureThatComparableExtensions { - public static void Is(this in Param param, T expected) where T : IComparable - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, T expected) where T : IComparable + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void Is(this in Param param, T expected, IComparer comparer) where T : IComparable - => Ensure.Comparable.Is(param.Value, expected, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsNot(this in Param param, T expected) where T : IComparable - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, T expected, IComparer comparer) where T : IComparable + { + Ensure.Comparable.Is(param.Value, expected, comparer, param.Name, param.OptsFn); - public static void IsNot(this in Param param, T expected, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsNot(param.Value, expected, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, T limit) where T : IComparable - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, T expected) where T : IComparable + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLt(this in Param param, T limit, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsLt(param.Value, limit, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsLte(this in Param param, T limit) where T : IComparable - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, T expected, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsNot(param.Value, expected, comparer, param.Name, param.OptsFn); - public static void IsLte(this in Param param, T limit, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsLte(param.Value, limit, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, T limit) where T : IComparable - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, T limit) where T : IComparable + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGt(this in Param param, T limit, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsGt(param.Value, limit, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsGte(this in Param param, T limit) where T : IComparable - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, T limit, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsLt(param.Value, limit, comparer, param.Name, param.OptsFn); - public static void IsGte(this in Param param, T limit, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsGte(param.Value, limit, comparer, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, T min, T max) where T : IComparable - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, T limit) where T : IComparable + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); - public static void IsInRange(this in Param param, T min, T max, IComparer comparer) where T : IComparable - => Ensure.Comparable.IsInRange(param.Value, min, max, comparer, param.Name, param.OptsFn); + return param; + } + + public static Param IsLte(this in Param param, T limit, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsLte(param.Value, limit, comparer, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, T limit) where T : IComparable + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, T limit, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsGt(param.Value, limit, comparer, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, T limit) where T : IComparable + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, T limit, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsGte(param.Value, limit, comparer, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, T min, T max) where T : IComparable + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, T min, T max, IComparer comparer) where T : IComparable + { + Ensure.Comparable.IsInRange(param.Value, min, max, comparer, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableIntExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableIntExtensions.cs index ce86d687..73b5f252 100644 --- a/src/projects/EnsureThat/EnsureThatComparableIntExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableIntExtensions.cs @@ -2,25 +2,53 @@ { public static class EnsureThatComparableIntExtensions { - public static void Is(this in Param param, int expected) - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, int expected) + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void IsNot(this in Param param, int expected) - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, int limit) - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, int expected) + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLte(this in Param param, int limit) - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, int limit) - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, int limit) + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGte(this in Param param, int limit) - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, int min, int max) - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, int limit) + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, int limit) + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, int limit) + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, int min, int max) + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatComparableLongExtensions.cs b/src/projects/EnsureThat/EnsureThatComparableLongExtensions.cs index de159601..20148a11 100644 --- a/src/projects/EnsureThat/EnsureThatComparableLongExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatComparableLongExtensions.cs @@ -2,25 +2,53 @@ { public static class EnsureThatComparableLongExtensions { - public static void Is(this in Param param, long expected) - => Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); + public static Param Is(this in Param param, long expected) + { + Ensure.Comparable.Is(param.Value, expected, param.Name, param.OptsFn); - public static void IsNot(this in Param param, long expected) - => Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in Param param, long limit) - => Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsNot(this in Param param, long expected) + { + Ensure.Comparable.IsNot(param.Value, expected, param.Name, param.OptsFn); - public static void IsLte(this in Param param, long limit) - => Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in Param param, long limit) - => Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + public static Param IsLt(this in Param param, long limit) + { + Ensure.Comparable.IsLt(param.Value, limit, param.Name, param.OptsFn); - public static void IsGte(this in Param param, long limit) - => Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in Param param, long min, long max) - => Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + public static Param IsLte(this in Param param, long limit) + { + Ensure.Comparable.IsLte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGt(this in Param param, long limit) + { + Ensure.Comparable.IsGt(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsGte(this in Param param, long limit) + { + Ensure.Comparable.IsGte(param.Value, limit, param.Name, param.OptsFn); + + return param; + } + + public static Param IsInRange(this in Param param, long min, long max) + { + Ensure.Comparable.IsInRange(param.Value, min, max, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatEnumExtensions.cs b/src/projects/EnsureThat/EnsureThatEnumExtensions.cs index a56df1c3..f4b70548 100644 --- a/src/projects/EnsureThat/EnsureThatEnumExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatEnumExtensions.cs @@ -10,7 +10,7 @@ public static class EnsureThatEnumExtensions /// /// /// Flags example: - /// + /// /// [Flags] /// enum Abc { /// A = 1, @@ -22,14 +22,22 @@ public static class EnsureThatEnumExtensions /// Abc.A | Abc.B IsDefined=true (due to Abc.AB) /// Abc.A | Abc.C IsDefined=false (A and C are both valid, the composite is valid due to ` attribute, but the composite is not a named enum value /// - public static void IsDefined(this in Param param) where T : struct, System.Enum - => Ensure.Enum.IsDefined(param.Value, param.Name, param.OptsFn); + public static Param IsDefined(this in Param param) where T : struct, System.Enum + { + Ensure.Enum.IsDefined(param.Value, param.Name, param.OptsFn); + + return param; + } /// /// Confirms that the is defined in the enum . /// Supports attribute. /// - public static void IsDefinedWithFlagsSupport(this in Param param) where T : struct, System.Enum - => Ensure.Enum.IsDefinedWithFlagsSupport(param.Value, param.Name, param.OptsFn); + public static Param IsDefinedWithFlagsSupport(this in Param param) where T : struct, System.Enum + { + Ensure.Enum.IsDefinedWithFlagsSupport(param.Value, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatStringExtensions.cs b/src/projects/EnsureThat/EnsureThatStringExtensions.cs index 142840b8..751bc619 100644 --- a/src/projects/EnsureThat/EnsureThatStringExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatStringExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; using JetBrains.Annotations; @@ -6,86 +7,194 @@ namespace EnsureThat { public static class EnsureThatStringExtensions { - public static void IsNotNull(this in StringParam param) - => Ensure.String.IsNotNull(param.Value, param.Name, param.OptsFn); + public static StringParam IsNotNull(this in StringParam param) + { + Ensure.String.IsNotNull(param.Value, param.Name, param.OptsFn); - public static void IsNotNullOrWhiteSpace(this in StringParam param) - => Ensure.String.IsNotNullOrWhiteSpace(param.Value, param.Name, param.OptsFn); + return param; + } - public static void IsNotNullOrEmpty(this in StringParam param) - => Ensure.String.IsNotNullOrEmpty(param.Value, param.Name, param.OptsFn); + public static StringParam IsNotNullOrWhiteSpace(this in StringParam param) + { + Ensure.String.IsNotNullOrWhiteSpace(param.Value, param.Name, param.OptsFn); - public static void IsNotEmptyOrWhiteSpace(this in StringParam param) - => Ensure.String.IsNotEmptyOrWhiteSpace(param.Value, param.Name, param.OptsFn); + return param; + } - public static void IsNotEmpty(this in StringParam param) - => Ensure.String.IsNotEmpty(param.Value, param.Name, param.OptsFn); - - public static void HasLength(this in StringParam param, int expected) - => Ensure.String.HasLength(param.Value, expected, param.Name, param.OptsFn); + public static StringParam IsNotNullOrEmpty(this in StringParam param) + { + Ensure.String.IsNotNullOrEmpty(param.Value, param.Name, param.OptsFn); - public static void HasLengthBetween(this in StringParam param, int minLength, int maxLength) - => Ensure.String.HasLengthBetween(param.Value, minLength, maxLength, param.Name, param.OptsFn); + return param; + } - public static void Matches(this in StringParam param, [RegexPattern] string match) - => Ensure.String.Matches(param.Value, match, param.Name, param.OptsFn); + public static StringParam IsNotEmptyOrWhiteSpace(this in StringParam param) + { + Ensure.String.IsNotEmptyOrWhiteSpace(param.Value, param.Name, param.OptsFn); - public static void Matches(this in StringParam param, [NotNull] Regex match) - => Ensure.String.Matches(param.Value, match, param.Name, param.OptsFn); + return param; + } + + public static StringParam IsNotEmpty(this in StringParam param) + { + Ensure.String.IsNotEmpty(param.Value, param.Name, param.OptsFn); + + return param; + } + + public static StringParam HasLength(this in StringParam param, int expected) + { + Ensure.String.HasLength(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam HasLengthBetween(this in StringParam param, int minLength, int maxLength) + { + Ensure.String.HasLengthBetween(param.Value, minLength, maxLength, param.Name, param.OptsFn); + + return param; + } + + public static StringParam Matches(this in StringParam param, [RegexPattern] string match) + { + Ensure.String.Matches(param.Value, match, param.Name, param.OptsFn); + + return param; + } + + public static StringParam Matches(this in StringParam param, [NotNull] Regex match) + { + Ensure.String.Matches(param.Value, match, param.Name, param.OptsFn); + + return param; + } [Obsolete("Use 'HasLength' instead. This will be removed in an upcoming version.")] - public static void SizeIs(this in StringParam param, int expected) - => Ensure.String.SizeIs(param.Value, expected, param.Name, param.OptsFn); + public static StringParam SizeIs(this in StringParam param, int expected) + { + Ensure.String.SizeIs(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam Is(this in StringParam param, string expected) + { + Ensure.String.Is(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsEqualTo(this in StringParam param, string expected) + { + Ensure.String.IsEqualTo(param.Value, expected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam Is(this in StringParam param, string expected, StringComparison comparison) + { + Ensure.String.Is(param.Value, expected, comparison, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsEqualTo(this in StringParam param, string expected, StringComparison comparison) + { + Ensure.String.IsEqualTo(param.Value, expected, comparison, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsNot(this in StringParam param, string notExpected) + { + Ensure.String.IsNot(param.Value, notExpected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsNotEqualTo(this in StringParam param, string notExpected) + { + Ensure.String.IsNotEqualTo(param.Value, notExpected, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsNot(this in StringParam param, string notExpected, StringComparison comparison) + { + Ensure.String.IsNot(param.Value, notExpected, comparison, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsNotEqualTo(this in StringParam param, string notExpected, StringComparison comparison) + { + Ensure.String.IsNotEqualTo(param.Value, notExpected, comparison, param.Name, param.OptsFn); + + return param; + } + + public static StringParam IsGuid(this in StringParam param) + { + Ensure.String.IsGuid(param.Value, param.Name, param.OptsFn); - public static void Is(this in StringParam param, string expected) - => Ensure.String.Is(param.Value, expected, param.Name, param.OptsFn); + return param; + } - public static void IsEqualTo(this in StringParam param, string expected) - => Ensure.String.IsEqualTo(param.Value, expected, param.Name, param.OptsFn); + public static StringParam StartsWith(this in StringParam param, [NotNull] string expectedStartsWith) + { + Ensure.String.StartsWith(param.Value, expectedStartsWith, param.Name, param.OptsFn); - public static void Is(this in StringParam param, string expected, StringComparison comparison) - => Ensure.String.Is(param.Value, expected, comparison, param.Name, param.OptsFn); + return param; + } - public static void IsEqualTo(this in StringParam param, string expected, StringComparison comparison) - => Ensure.String.IsEqualTo(param.Value, expected, comparison, param.Name, param.OptsFn); + public static StringParam StartsWith(this in StringParam param, [NotNull] string expectedStartsWith, StringComparison comparison) + { + Ensure.String.StartsWith(param.Value, expectedStartsWith, comparison, param.Name, param.OptsFn); - public static void IsNot(this in StringParam param, string notExpected) - => Ensure.String.IsNot(param.Value, notExpected, param.Name, param.OptsFn); + return param; + } - public static void IsNotEqualTo(this in StringParam param, string notExpected) - => Ensure.String.IsNotEqualTo(param.Value, notExpected, param.Name, param.OptsFn); + public static StringParam IsLt(this in StringParam param, string limit, StringComparison comparison) + { + Ensure.String.IsLt(param.Value, limit, comparison, param.Name, param.OptsFn); - public static void IsNot(this in StringParam param, string notExpected, StringComparison comparison) - => Ensure.String.IsNot(param.Value, notExpected, comparison, param.Name, param.OptsFn); + return param; + } - public static void IsNotEqualTo(this in StringParam param, string notExpected, StringComparison comparison) - => Ensure.String.IsNotEqualTo(param.Value, notExpected, comparison, param.Name, param.OptsFn); + public static StringParam IsLte(this in StringParam param, string limit, StringComparison comparison) + { + Ensure.String.IsLte(param.Value, limit, comparison, param.Name, param.OptsFn); - public static void IsGuid(this in StringParam param) - => Ensure.String.IsGuid(param.Value, param.Name, param.OptsFn); + return param; + } - public static void StartsWith(this in StringParam param, [NotNull] string expectedStartsWith) - => Ensure.String.StartsWith(param.Value, expectedStartsWith, param.Name, param.OptsFn); + public static StringParam IsGt(this in StringParam param, string limit, StringComparison comparison) + { + Ensure.String.IsGt(param.Value, limit, comparison, param.Name, param.OptsFn); - public static void StartsWith(this in StringParam param, [NotNull] string expectedStartsWith, StringComparison comparison) - => Ensure.String.StartsWith(param.Value, expectedStartsWith, comparison, param.Name, param.OptsFn); + return param; + } - public static void IsLt(this in StringParam param, string limit, StringComparison comparison) - => Ensure.String.IsLt(param.Value, limit, comparison, param.Name, param.OptsFn); + public static StringParam IsGte(this in StringParam param, string limit, StringComparison comparison) + { + Ensure.String.IsGte(param.Value, limit, comparison, param.Name, param.OptsFn); - public static void IsLte(this in StringParam param, string limit, StringComparison comparison) - => Ensure.String.IsLte(param.Value, limit, comparison, param.Name, param.OptsFn); + return param; + } - public static void IsGt(this in StringParam param, string limit, StringComparison comparison) - => Ensure.String.IsGt(param.Value, limit, comparison, param.Name, param.OptsFn); + public static StringParam IsInRange(this in StringParam param, string min, string max, StringComparison comparison) + { + Ensure.String.IsInRange(param.Value, min, max, comparison, param.Name, param.OptsFn); - public static void IsGte(this in StringParam param, string limit, StringComparison comparison) - => Ensure.String.IsGte(param.Value, limit, comparison, param.Name, param.OptsFn); + return param; + } - public static void IsInRange(this in StringParam param, string min, string max, StringComparison comparison) - => Ensure.String.IsInRange(param.Value, min, max, comparison, param.Name, param.OptsFn); + public static StringParam IsAllLettersOrDigits(this in StringParam param) + { + Ensure.String.IsAllLettersOrDigits(param.Value, param.Name, param.OptsFn); - public static void IsAllLettersOrDigits(this in StringParam param) - => Ensure.String.IsAllLettersOrDigits(param.Value, param.Name, param.OptsFn); + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatTypeExtensions.cs b/src/projects/EnsureThat/EnsureThatTypeExtensions.cs index 7b10b888..21ffddde 100644 --- a/src/projects/EnsureThat/EnsureThatTypeExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatTypeExtensions.cs @@ -1,50 +1,106 @@ using System; -using JetBrains.Annotations; +using System.Diagnostics.CodeAnalysis; namespace EnsureThat { public static class EnsureThatTypeExtensions { - public static void IsInt(this in TypeParam param) - => Ensure.Type.IsInt(param.Type, param.Name, param.OptsFn); + public static TypeParam IsInt(this in TypeParam param) + { + Ensure.Type.IsInt(param.Type, param.Name, param.OptsFn); - public static void IsShort(this in TypeParam param) - => Ensure.Type.IsShort(param.Type, param.Name, param.OptsFn); + return param; + } - public static void IsDecimal(this in TypeParam param) - => Ensure.Type.IsDecimal(param.Type, param.Name, param.OptsFn); + public static TypeParam IsShort(this in TypeParam param) + { + Ensure.Type.IsShort(param.Type, param.Name, param.OptsFn); - public static void IsDouble(this in TypeParam param) - => Ensure.Type.IsDouble(param.Type, param.Name, param.OptsFn); + return param; + } - public static void IsFloat(this in TypeParam param) - => Ensure.Type.IsFloat(param.Type, param.Name, param.OptsFn); + public static TypeParam IsDecimal(this in TypeParam param) + { + Ensure.Type.IsDecimal(param.Type, param.Name, param.OptsFn); - public static void IsBool(this in TypeParam param) - => Ensure.Type.IsBool(param.Type, param.Name, param.OptsFn); + return param; + } - public static void IsDateTime(this in TypeParam param) - => Ensure.Type.IsDateTime(param.Type, param.Name, param.OptsFn); + public static TypeParam IsDouble(this in TypeParam param) + { + Ensure.Type.IsDouble(param.Type, param.Name, param.OptsFn); - public static void IsString(this in TypeParam param) - => Ensure.Type.IsString(param.Type, param.Name, param.OptsFn); + return param; + } - public static void IsOfType(this in TypeParam param, [NotNull] Type expectedType) - => Ensure.Type.IsOfType(param.Type, expectedType, param.Name, param.OptsFn); + public static TypeParam IsFloat(this in TypeParam param) + { + Ensure.Type.IsFloat(param.Type, param.Name, param.OptsFn); - public static void IsNotOfType(this in TypeParam param, Type expectedType) - => Ensure.Type.IsNotOfType(param.Type, expectedType, param.Name, param.OptsFn); + return param; + } - public static void IsAssignableToType(this in TypeParam param, [NotNull] Type expectedType) - => Ensure.Type.IsAssignableToType(param.Type, expectedType, param.Name, param.OptsFn); + public static TypeParam IsBool(this in TypeParam param) + { + Ensure.Type.IsBool(param.Type, param.Name, param.OptsFn); - public static void IsNotAssignableToType(this in TypeParam param, Type expectedType) - => Ensure.Type.IsNotAssignableToType(param.Type, expectedType, param.Name, param.OptsFn); + return param; + } - public static void IsClass(this in Param param) - => Ensure.Type.IsClass(param.Value, param.Name, param.OptsFn); + public static TypeParam IsDateTime(this in TypeParam param) + { + Ensure.Type.IsDateTime(param.Type, param.Name, param.OptsFn); - public static void IsClass(this in TypeParam param) - => Ensure.Type.IsClass(param.Type, param.Name, param.OptsFn); + return param; + } + + public static TypeParam IsString(this in TypeParam param) + { + Ensure.Type.IsString(param.Type, param.Name, param.OptsFn); + + return param; + } + + public static TypeParam IsOfType(this in TypeParam param, [NotNull] Type expectedType) + { + Ensure.Type.IsOfType(param.Type, expectedType, param.Name, param.OptsFn); + + return param; + } + + public static TypeParam IsNotOfType(this in TypeParam param, Type expectedType) + { + Ensure.Type.IsNotOfType(param.Type, expectedType, param.Name, param.OptsFn); + + return param; + } + + public static TypeParam IsAssignableToType(this in TypeParam param, [NotNull] Type expectedType) + { + Ensure.Type.IsAssignableToType(param.Type, expectedType, param.Name, param.OptsFn); + + return param; + } + + public static TypeParam IsNotAssignableToType(this in TypeParam param, Type expectedType) + { + Ensure.Type.IsNotAssignableToType(param.Type, expectedType, param.Name, param.OptsFn); + + return param; + } + + public static Param IsClass(this in Param param) + { + Ensure.Type.IsClass(param.Value, param.Name, param.OptsFn); + + return param; + } + + public static TypeParam IsClass(this in TypeParam param) + { + Ensure.Type.IsClass(param.Type, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/EnsureThatValueTypeExtensions.cs b/src/projects/EnsureThat/EnsureThatValueTypeExtensions.cs index acf57f04..030fff3a 100644 --- a/src/projects/EnsureThat/EnsureThatValueTypeExtensions.cs +++ b/src/projects/EnsureThat/EnsureThatValueTypeExtensions.cs @@ -4,19 +4,39 @@ namespace EnsureThat { public static class EnsureThatValueTypeExtensions { - public static void IsTrue(this in Param param) - => Ensure.Bool.IsTrue(param.Value, param.Name, param.OptsFn); + public static Param IsTrue(this in Param param) + { + Ensure.Bool.IsTrue(param.Value, param.Name, param.OptsFn); - public static void IsFalse(this in Param param) - => Ensure.Bool.IsFalse(param.Value, param.Name, param.OptsFn); + return param; + } - public static void IsNotDefault(this in Param param) where T : struct - => Ensure.Any.IsNotDefault(param.Value, param.Name, param.OptsFn); + public static Param IsFalse(this in Param param) + { + Ensure.Bool.IsFalse(param.Value, param.Name, param.OptsFn); - public static void IsNotNull(this in Param param) where T : struct - => Ensure.Any.IsNotNull(param.Value, param.Name, param.OptsFn); + return param; + } - public static void IsNotEmpty(this in Param param) - => Ensure.Guid.IsNotEmpty(param.Value, param.Name, param.OptsFn); + public static Param IsNotDefault(this in Param param) where T : struct + { + Ensure.Any.IsNotDefault(param.Value, param.Name, param.OptsFn); + + return param; + } + + public static Param IsNotNull(this in Param param) where T : struct + { + Ensure.Any.IsNotNull(param.Value, param.Name, param.OptsFn); + + return param; + } + + public static Param IsNotEmpty(this in Param param) + { + Ensure.Guid.IsNotEmpty(param.Value, param.Name, param.OptsFn); + + return param; + } } -} \ No newline at end of file +} diff --git a/src/projects/EnsureThat/IExceptionFactory.cs b/src/projects/EnsureThat/IExceptionFactory.cs index 9c59f560..99ce4d2f 100644 --- a/src/projects/EnsureThat/IExceptionFactory.cs +++ b/src/projects/EnsureThat/IExceptionFactory.cs @@ -1,5 +1,5 @@ using System; -using JetBrains.Annotations; +using System.Diagnostics.CodeAnalysis; namespace EnsureThat { diff --git a/src/projects/EnsureThat/Internals/DefaultExceptionFactory.cs b/src/projects/EnsureThat/Internals/DefaultExceptionFactory.cs index 90a692e6..19e8afd2 100644 --- a/src/projects/EnsureThat/Internals/DefaultExceptionFactory.cs +++ b/src/projects/EnsureThat/Internals/DefaultExceptionFactory.cs @@ -1,6 +1,6 @@ using System; -using JetBrains.Annotations; -using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; namespace EnsureThat.Internals { @@ -12,7 +12,7 @@ public Exception ArgumentException(string defaultMessage, string paramName, Opts { if (optsFn != null) { - var opts = optsFn(new EnsureOptions()); + var opts = optsFn(in EnsureOptions.Default); if (opts.CustomExceptionFactory != null) return opts.CustomExceptionFactory(defaultMessage, paramName); @@ -33,7 +33,7 @@ public Exception ArgumentNullException(string defaultMessage, string paramName, { if (optsFn != null) { - var opts = optsFn(new EnsureOptions()); + var opts = optsFn(in EnsureOptions.Default); if (opts.CustomExceptionFactory != null) return opts.CustomExceptionFactory(defaultMessage, paramName); @@ -54,7 +54,7 @@ public Exception ArgumentOutOfRangeException(string defaultMessage, stri { if (optsFn != null) { - var opts = optsFn(new EnsureOptions()); + var opts = optsFn(in EnsureOptions.Default); if (opts.CustomExceptionFactory != null) return opts.CustomExceptionFactory(defaultMessage, paramName); diff --git a/src/projects/EnsureThat/OptsFn.cs b/src/projects/EnsureThat/OptsFn.cs index 3afcf97c..52cf64ad 100644 --- a/src/projects/EnsureThat/OptsFn.cs +++ b/src/projects/EnsureThat/OptsFn.cs @@ -1,4 +1,4 @@ namespace EnsureThat { - public delegate EnsureOptions OptsFn(EnsureOptions options); -} \ No newline at end of file + public delegate EnsureOptions OptsFn(in EnsureOptions options); +} diff --git a/src/projects/EnsureThat/Param.cs b/src/projects/EnsureThat/Param.cs index 7ce75899..73cd2d4a 100644 --- a/src/projects/EnsureThat/Param.cs +++ b/src/projects/EnsureThat/Param.cs @@ -1,5 +1,5 @@ using System; -using JetBrains.Annotations; +using System.Diagnostics.CodeAnalysis; namespace EnsureThat { diff --git a/src/tests/Benchmarks/Benchmarks.csproj b/src/tests/Benchmarks/Benchmarks.csproj index 4ae6ee6e..9f0a9b24 100644 --- a/src/tests/Benchmarks/Benchmarks.csproj +++ b/src/tests/Benchmarks/Benchmarks.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/tests/Benchmarks/Program.cs b/src/tests/Benchmarks/Program.cs index 0ff4ed1c..37d26dbe 100644 --- a/src/tests/Benchmarks/Program.cs +++ b/src/tests/Benchmarks/Program.cs @@ -206,17 +206,17 @@ public void IntsHasItemsViaEnforcer() [Benchmark(Baseline = true)] [BenchmarkCategory("Any.IsNotNull")] public void ThingIsNotNull() - => BaseLines.ThingIsNotNullViaThat(new MyThing()); + => BaseLines.ThingIsNotNullViaThat(_things[0]); [Benchmark] [BenchmarkCategory("Any.IsNotNull")] public void ThingIsNotNullViaThat() - => Ensure.That(new MyThing(), "test").IsNotNull(); + => Ensure.That(_things[0], "test").IsNotNull(); [Benchmark] [BenchmarkCategory("Any.IsNotNull")] public void ThingIsNotNullViaEnforcer() - => Ensure.Any.IsNotNull(new MyThing(), ParamName); + => Ensure.Any.IsNotNull(_things[0], ParamName); [Benchmark(Baseline = true)] [BenchmarkCategory("Things.HasItems")] @@ -256,7 +256,7 @@ public void AnyHasValueWhenStringBaseLine() [Benchmark] [BenchmarkCategory("Any.string.HasValue")] public void AnyHasValueWhenString() - => Ensure.Any.HasValue(string.Empty, ParamName); + => Ensure.Any.HasValue(string.Empty, ParamName); private class MyThing { @@ -264,4 +264,4 @@ private class MyThing public int MyInt { get; set; } } } -} \ No newline at end of file +} diff --git a/src/tests/UnitTests/DefaultExceptionFactoryTests.cs b/src/tests/UnitTests/DefaultExceptionFactoryTests.cs index ecbb3950..517e424b 100644 --- a/src/tests/UnitTests/DefaultExceptionFactoryTests.cs +++ b/src/tests/UnitTests/DefaultExceptionFactoryTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using EnsureThat; using EnsureThat.Internals; using FluentAssertions; using Xunit; @@ -28,7 +29,7 @@ public void ArgumentException_UsesExceptionFactory_WhenOptionsAlsoContainsCustom => _sut.ArgumentException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException) .WithExceptionFactory((_, __) => _exceptionFactoryException)) @@ -40,7 +41,7 @@ public void ArgumentException_UsesCustomException_WhenOptionsAlsoContainsCustomM => _sut.ArgumentException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException)) .Should() @@ -51,7 +52,7 @@ public void ArgumentException_UsesCustomMessage_WhenOptionsHasNoOtherConfig() => _sut.ArgumentException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage)) .Should() .BeEquivalentTo(new ArgumentException(CustomMessage, ParamName)); @@ -69,7 +70,7 @@ public void ArgumentNullException_UsesExceptionFactory_WhenOptionsAlsoContainsCu => _sut.ArgumentNullException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException) .WithExceptionFactory((_, __) => _exceptionFactoryException)) @@ -81,7 +82,7 @@ public void ArgumentNullException_UsesCustomException_WhenOptionsAlsoContainsCus => _sut.ArgumentNullException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException)) .Should() @@ -92,7 +93,7 @@ public void ArgumentNullException_UsesCustomMessage_WhenOptionsHasNoOtherConfig( => _sut.ArgumentNullException( DefaultMessage, ParamName, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage)) .Should() .BeEquivalentTo(new ArgumentNullException(ParamName, CustomMessage)); @@ -112,7 +113,7 @@ public void ArgumentOutOfRangeException_UsesExceptionFactory_WhenOptionsAlsoCont DefaultMessage, ParamName, DummyValue, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException) .WithExceptionFactory((_, __) => _exceptionFactoryException)) @@ -125,7 +126,7 @@ public void ArgumentOutOfRangeException_UsesCustomException_WhenOptionsAlsoConta DefaultMessage, ParamName, DummyValue, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage) .WithException(_customException)) .Should() @@ -137,7 +138,7 @@ public void ArgumentOutOfRangeException_UsesCustomMessage_WhenOptionsHasNoOtherC DefaultMessage, ParamName, DummyValue, - o => o + (in EnsureOptions o) => o .WithMessage(CustomMessage)) .Should() .BeEquivalentTo(new ArgumentOutOfRangeException(ParamName, DummyValue, CustomMessage)); diff --git a/src/tests/UnitTests/OptsTests.cs b/src/tests/UnitTests/OptsTests.cs index 33d6bd03..7b8a6d68 100644 --- a/src/tests/UnitTests/OptsTests.cs +++ b/src/tests/UnitTests/OptsTests.cs @@ -16,13 +16,13 @@ public class WithCustomExceptionFactoryTests : UnitTestBase public void ThrowsTheCustomExceptionFromTheFactory() { object value = null; - OptsFn options = o => o.WithExceptionFactory((_, __) => new KeyNotFoundException()); + EnsureOptions CreateOptions(in EnsureOptions o) => o.WithExceptionFactory((_, __) => new KeyNotFoundException()); var actions = new Action[] { - () => Ensure.Any.IsNotNull(value, ParamName, options), - () => EnsureArg.IsNotNull(value, ParamName, options), - () => Ensure.That(value, ParamName, options).IsNotNull() + () => Ensure.Any.IsNotNull(value, ParamName, CreateOptions), + () => EnsureArg.IsNotNull(value, ParamName, CreateOptions), + () => Ensure.That(value, ParamName, CreateOptions).IsNotNull() }.ToList(); actions.ForEach(a => a.Should().Throw()); @@ -32,16 +32,17 @@ public void ThrowsTheCustomExceptionFromTheFactory() public void WhenWithMessageAndCustomExceptionAreSpecified_ThrowsTheCustomExceptionFromTheFactory() { object value = null; - OptsFn options = o => o + + EnsureOptions CreateOptions(in EnsureOptions o) => o .WithMessage("Foo bar") .WithException(new KeyNotFoundException()) .WithExceptionFactory((_, __) => new InvalidTimeZoneException()); var actions = new Action[] { - () => Ensure.Any.IsNotNull(value, ParamName, options), - () => EnsureArg.IsNotNull(value, ParamName, options), - () => Ensure.That(value, ParamName,options).IsNotNull() + () => Ensure.Any.IsNotNull(value, ParamName, CreateOptions), + () => EnsureArg.IsNotNull(value, ParamName, CreateOptions), + () => Ensure.That(value, ParamName,CreateOptions).IsNotNull() }.ToList(); actions.ForEach(a => a.Should().Throw().And.Message.Should().NotContain("Foo Bar")); @@ -54,13 +55,13 @@ public class WithExceptionTests : UnitTestBase public void ThrowsTheCustomException() { object value = null; - OptsFn options = o => o.WithException(new KeyNotFoundException()); + EnsureOptions CreateOptions(in EnsureOptions o) => o.WithException(new KeyNotFoundException()); var actions = new Action[] { - () => Ensure.Any.IsNotNull(value, ParamName, options), - () => EnsureArg.IsNotNull(value, ParamName, options), - () => Ensure.That(value, ParamName, options).IsNotNull() + () => Ensure.Any.IsNotNull(value, ParamName, CreateOptions), + () => EnsureArg.IsNotNull(value, ParamName, CreateOptions), + () => Ensure.That(value, ParamName, CreateOptions).IsNotNull() }.ToList(); actions.ForEach(a => a.Should().Throw()); @@ -70,13 +71,13 @@ public void ThrowsTheCustomException() public void WhenWithMessageIsSpecified_ThrowsTheCustomExceptionButDoesNotUseTheExtraMessage() { object value = null; - OptsFn options = o => o.WithMessage("Foo bar").WithException(new KeyNotFoundException()); + EnsureOptions CreateOptions(in EnsureOptions o) => o.WithMessage("Foo bar").WithException(new KeyNotFoundException()); var actions = new Action[] { - () => Ensure.Any.IsNotNull(value, ParamName, options), - () => EnsureArg.IsNotNull(value, ParamName, options), - () => Ensure.That(value, ParamName,options).IsNotNull() + () => Ensure.Any.IsNotNull(value, ParamName, CreateOptions), + () => EnsureArg.IsNotNull(value, ParamName, CreateOptions), + () => Ensure.That(value, ParamName, CreateOptions).IsNotNull() }.ToList(); actions.ForEach(a => a.Should().Throw().And.Message.Should().NotContain("Foo Bar")); @@ -89,12 +90,12 @@ public class WithMessageTests : UnitTestBase public void ThrowsExceptionWithTheCustomMessage() { object value = null; - OptsFn options = o => o.WithMessage("Foo bar is some dummy text."); + EnsureOptions CreateOptions(in EnsureOptions o) => o.WithMessage("Foo bar is some dummy text."); ShouldThrow("Foo bar is some dummy text.", - () => Ensure.Any.IsNotNull(value, ParamName, options), - () => EnsureArg.IsNotNull(value, ParamName, options), - () => Ensure.That(value, ParamName, options).IsNotNull()); + () => Ensure.Any.IsNotNull(value, ParamName, CreateOptions), + () => EnsureArg.IsNotNull(value, ParamName, CreateOptions), + () => Ensure.That(value, ParamName, CreateOptions).IsNotNull()); } } } diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index e96df18d..1642c0d7 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -1,14 +1,14 @@  - net452;netcoreapp3.1;net5.0 + netcoreapp3.1;net5.0 false true - - + + all