Skip to content

Commit

Permalink
#28: Synergy.Contracts: Added Fail.IfEmpty(text) method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Feb 3, 2024
1 parent 1fbce88 commit d7829ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
value: object [NotNull, NotNull]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
value: object [NotNull, NotNull]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
value: object [NotNull, NotNull]
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 @@ -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));
Expand Down

0 comments on commit d7829ee

Please sign in to comment.