Created
October 11, 2023 06:01
-
-
Save danielmackay/7aef664a57e2740bbdde891bda86d86e to your computer and use it in GitHub Desktop.
Guard Clause Custom Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringLengthGuard | |
{ | |
public static string StringLength(this IGuardClause guardClause, | |
string input, | |
int maxLength, | |
[CallerArgumentExpression("input")] string? parameterName = null) | |
{ | |
if (input?.Length > maxLength) | |
throw new ArgumentException($"Cannot exceed string length of {maxLength}", parameterName); | |
return input!; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment