From fd1dde80ff2e7311c436996e10c9275f9a67980d Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Sat, 3 Feb 2024 18:03:04 +0100 Subject: [PATCH] #28: Synergy.Contracts: Added text.OrFailIfTooLong(max length); method --- ...of.Synergy.Contracts.DotNet6_0.verified.md | 2 +- ...of.Synergy.Contracts.DotNet7_0.verified.md | 2 +- ...of.Synergy.Contracts.DotNet8_0.verified.md | 2 +- .../Failures/FailStringTest.cs | Bin 16450 -> 16806 bytes .../Synergy.Contracts/Failures/FailString.cs | 9 +++++++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md index a9b092f..1199419 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md @@ -248,7 +248,7 @@ - Fail.OrFailIfTooLong( value: string [CanBeNull], maxLength: int, - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation] - Fail.OrFailIfWhiteSpace( value: string? [AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md index a9b092f..1199419 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md @@ -248,7 +248,7 @@ - Fail.OrFailIfTooLong( value: string [CanBeNull], maxLength: int, - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation] - Fail.OrFailIfWhiteSpace( value: string? [AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md index a9b092f..1199419 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md @@ -248,7 +248,7 @@ - Fail.OrFailIfTooLong( value: string [CanBeNull], maxLength: int, - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation] - Fail.OrFailIfWhiteSpace( value: string? [AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs index 162d941de4532a94d096123dedce0d5141bcf9af..599dbdabd97ab72733f6c65f733743c88bdd4f73 100644 GIT binary patch delta 63 zcmX@qz__fLaYMB6tEY4TiNfyw`wI41KeNo|fcmSO~R&Khe?HZ)9` R%&jXlx!*!+^IMZpZU7Zl7gzuQ delta 39 vcmZ41%y_7QaYMB6=28xAwB_`KP%S>J`DKnX0mv3^txzy%BvrujTB1a8k diff --git a/Contracts/Synergy.Contracts/Failures/FailString.cs b/Contracts/Synergy.Contracts/Failures/FailString.cs index e5f522a..a748b47 100644 --- a/Contracts/Synergy.Contracts/Failures/FailString.cs +++ b/Contracts/Synergy.Contracts/Failures/FailString.cs @@ -186,7 +186,7 @@ public static void IfTooLong( #else string name #endif - ) + ) { Fail.RequiresArgumentName(name); @@ -211,7 +211,12 @@ string name public static string OrFailIfTooLong( [CanBeNull] this string value, int maxLength, - [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name) +#if NET6_0_OR_GREATER + [System.Runtime.CompilerServices.CallerArgumentExpression("value")] string? name = null +#else + string name +#endif + ) { Fail.IfTooLong(value, maxLength, name); return value;