From d7829eec9a8716e7aa0c9cca3015898092063df7 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Sat, 3 Feb 2024 17:40:00 +0100 Subject: [PATCH] #28: Synergy.Contracts: Added Fail.IfEmpty(text) 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 14224 -> 14876 bytes .../Synergy.Contracts/Failures/FailString.cs | 11 +++++++++-- 5 files changed, 12 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 f0757f9..2982372 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 @@ -131,7 +131,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEnumNotDefined( value: object [NotNull, NotNull] 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 3afacc5..501cd40 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 @@ -131,7 +131,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEnumNotDefined( value: object [NotNull, NotNull] 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 3afacc5..501cd40 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 @@ -131,7 +131,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEnumNotDefined( value: object [NotNull, NotNull] diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs index af424bf440e8e41a9f6eeba01ae74f6fb419159a..7df97261fadf5c6af03e305263a0cf3369a42dc5 100644 GIT binary patch delta 77 zcmbP`Kc{5FM&8N#tQRI%3JJ0MF(fkNGNew{U~`=OUiQXhX+e?6-(^KM_wycLocy1O fWAc73KCob;hS%hL)(JpO3X{JpzSt}+SgHm9N^%?} delta 36 ucmV+<0NekZbdYbbu?>?y6xfrwB7l>f6&RC`8bp&15O9-40zR{!5`8Bkpbkj@ diff --git a/Contracts/Synergy.Contracts/Failures/FailString.cs b/Contracts/Synergy.Contracts/Failures/FailString.cs index 24ed475..3a86a6e 100644 --- a/Contracts/Synergy.Contracts/Failures/FailString.cs +++ b/Contracts/Synergy.Contracts/Failures/FailString.cs @@ -43,8 +43,15 @@ string argumentName [AssertionMethod] [ContractAnnotation("value: null => halt")] public static void IfEmpty( - [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value, - [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name) + [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] + string value, +#if NET6_0_OR_GREATER + [System.Runtime.CompilerServices.CallerArgumentExpression("value")] + string? name = null +#else + string name +#endif + ) { Fail.RequiresArgumentName(name); Fail.IfEmpty(value, Violation.WhenEmpty(name));