From 1fbce8860b28d5e19bf6e7dd32c5b5aca9ced397 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Sat, 3 Feb 2024 17:32:46 +0100 Subject: [PATCH] #28: Synergy.Contracts: Added Fail.IfArgumentEmpty(name) 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/Doubles/Contractor.cs | 8 ++++---- .../Failures/FailStringTest.cs | Bin 6615 -> 14224 bytes .../Synergy.Contracts/Failures/FailString.cs | 11 +++++++++-- 6 files changed, 16 insertions(+), 9 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 8c335b0..f0757f9 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 @@ -76,7 +76,7 @@ ) : T? [Extension, NotNull, AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( argumentValue: string [CanBeNull, AssertionCondition], - argumentName: string [NotNull, NotNull] + argumentName: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( value: Guid, 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 4e658d2..3afacc5 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 @@ -76,7 +76,7 @@ ) : T? [Extension, NotNull, AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( argumentValue: string [CanBeNull, AssertionCondition], - argumentName: string [NotNull, NotNull] + argumentName: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( value: Guid, 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 4e658d2..3afacc5 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 @@ -76,7 +76,7 @@ ) : T? [Extension, NotNull, AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( argumentValue: string [CanBeNull, AssertionCondition], - argumentName: string [NotNull, NotNull] + argumentName: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.IfArgumentEmpty( value: Guid, diff --git a/Contracts/Synergy.Contracts.Test/Failures/Doubles/Contractor.cs b/Contracts/Synergy.Contracts.Test/Failures/Doubles/Contractor.cs index db37266..a6b8643 100644 --- a/Contracts/Synergy.Contracts.Test/Failures/Doubles/Contractor.cs +++ b/Contracts/Synergy.Contracts.Test/Failures/Doubles/Contractor.cs @@ -8,7 +8,7 @@ public class Contractor [NotNull, Pure] public static Contractor CreateCompany([NotNull] string name) { - Fail.IfArgumentEmpty(name, nameof(name)); + Fail.IfArgumentEmpty(name); return new Contractor { @@ -21,7 +21,7 @@ public static Contractor CreateCompany([NotNull] string name) [NotNull, Pure] public static Contractor CreatePerson([NotNull] string firstName, [NotNull] string lastName) { - Fail.IfArgumentEmpty(firstName, nameof(firstName)); + Fail.IfArgumentEmpty(firstName); Fail.IfArgumentWhiteSpace(lastName, nameof(lastName)); return new Contractor() @@ -70,8 +70,8 @@ public string GetCity() public void SetPersonName([NotNull] string firstName, [NotNull] string lastName) { - Fail.IfArgumentEmpty(firstName, nameof(firstName)); - Fail.IfArgumentEmpty(lastName, nameof(lastName)); + Fail.IfArgumentEmpty(firstName); + Fail.IfArgumentEmpty(lastName); throw Fail.Because("Not implemented yet"); } diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs index 94794bab34cf3d88aaf3455d1ddb70b0bea28f69..af424bf440e8e41a9f6eeba01ae74f6fb419159a 100644 GIT binary patch literal 14224 zcmeHOTTc@~6h6=VicNiRNwgY$^pb$0!6+nx`k+3PT5BT|QYwnZpYG-RW;o1VW{2Hn zX}3TKl+Ny)IrsC;+1bDUCWF-Ivob3@+Xt`Y9&$}=;65465x-bB8d zb(V0w2i^wY;{gBl@t@_|@-qbgmhUmBkOOi~4z|r4OPPG_g6D}DTasUpAUgSZe|qOL z-1P&q?R_5;_Z(ns2NWoMgx_7PbBLb^TwB^(W_7DoUD>UXTu;}%VYnHBCbjG+b!A;X zLw^(4=bMq7lC9yt1AHEXD@RvpIT?~%=dV67d=FsteIq5c8J}u+AM3_JiL56ixmlKF z@vWKG*b&wn$tOq|mhBzxn#vd10C)7m7&@j^)mwWRt-OUiwCey|j%Dhw>ETjI$y1y9&E8wvs;j z)=;7+Db2OqDvzOoyj;qie#VeKl1K6wf7Kt)@}k&Cmh>>E%UhtMQD=Q3q<5d@m9u3N z!}=}zSuB}aXA7RXCa;4wT7j0+HlRjhkIg98I_~YlznGc$Y5mO4=Wmbh^E_YH*ki7+ zwP51OMn4b>Hk;DN>Dkw@I*(Yr+|f7xXtSBZRo`ao-4^ms-&7Xnuvp%oWG2l^ACa-< zTLI@$Plyt;wL-r)!B26v&#!v}bz}_W!d$0V&4<9kXwLbMZ|-7M5GRX6YZjqrD*$&D z#M8bU6~bouiry|%XVzTws{4wW<}~D=W&Oau0eJ6zo>D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f?MTkGDs&KOZKsozMDMjI(?(y3A&y3a&WMVlFsKwP%!r}_EK~GH>c(hZmIES?b$V* ze&)_sA??j+%pax}X`-`Emm*xa7E?|mnZK!3frL&jZ_M3PLsd$Rm#s>+H!ej^qCQM* zTn0KA)3PnGXV$ch9eBw`Ty#5c0-A?l&o7E>MkzcD9t{Q2Yz=Wzw21hWOq@;mw!Y>* z$Lx%B;Fd3w%%Pw!SP^~er!P`N)NV0-g)HzxM2^N6fhR~`1>3D4r}m5yCD9`iL|M_bZmwXe fAzq+1HD-2vD_sqt$GA#vwr1wkNhGv__s08wmy2%y diff --git a/Contracts/Synergy.Contracts/Failures/FailString.cs b/Contracts/Synergy.Contracts/Failures/FailString.cs index a34df95..24ed475 100644 --- a/Contracts/Synergy.Contracts/Failures/FailString.cs +++ b/Contracts/Synergy.Contracts/Failures/FailString.cs @@ -14,8 +14,15 @@ static partial class Fail [AssertionMethod] [ContractAnnotation("argumentValue: null => halt")] public static void IfArgumentEmpty( - [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string argumentValue, - [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string argumentName) + [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] + string argumentValue, +#if NET6_0_OR_GREATER + [System.Runtime.CompilerServices.CallerArgumentExpression("argumentValue")] + string? argumentName = null +#else + string argumentName +#endif + ) { Fail.RequiresArgumentName(argumentName); Fail.IfArgumentNull(argumentValue, argumentName);