Skip to content

Commit

Permalink
#28: Synergy.Contracts: Added text.OrFailIfTooLong(max length); method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Feb 3, 2024
1 parent bb50fc4 commit fd1dde8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Binary file modified Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs
Binary file not shown.
9 changes: 7 additions & 2 deletions Contracts/Synergy.Contracts/Failures/FailString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void IfTooLong(
#else
string name
#endif
)
)
{
Fail.RequiresArgumentName(name);

Expand All @@ -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;
Expand Down

0 comments on commit fd1dde8

Please sign in to comment.