Skip to content

Commit

Permalink
#28: Synergy.Contracts: Added Fail.IfArgumentEmpty(name) method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Feb 3, 2024
1 parent cba2fee commit 1fbce88
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down Expand Up @@ -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");
}
Expand Down
Binary file modified Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs
Binary file not shown.
11 changes: 9 additions & 2 deletions Contracts/Synergy.Contracts/Failures/FailString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1fbce88

Please sign in to comment.