Skip to content

Commit

Permalink
chore: final cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kenny Pflug <[email protected]>
  • Loading branch information
feO2x committed Oct 27, 2024
1 parent 9eaf70f commit 8a53d51
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public string ImperativeVersion()

[Benchmark]
public string LightGuardClausesCustomException() =>
X.MustBe(Y, StringComparisonType.OrdinalIgnoreWhiteSpace, (x, y) => new Exception("The strings are not equal."));
X.MustBe(Y, StringComparisonType.OrdinalIgnoreWhiteSpace, (_, _, _) => new Exception("The strings are not equal."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public string ImperativeVersion()

[Benchmark]
public string LightGuardClausesCustomException() =>
X.MustNotBe(Y, StringComparisonType.OrdinalIgnoreCaseIgnoreWhiteSpace, (x, y) => new Exception("The strings are equal."));
X.MustNotBe(Y, StringComparisonType.OrdinalIgnoreCaseIgnoreWhiteSpace, (_, _, _) => new Exception("The strings are equal."));
}
}
6 changes: 4 additions & 2 deletions Code/Light.GuardClauses.Tests/StringAssertions/MustBeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static void StringsNotEqualIgnoreWhiteSpace(string first, string second,
public static void CustomException() =>
Test.CustomException("Foo",
"Bar",
(x, y, exceptionFactory) => x.MustBe(y, StringComparison.Ordinal, exceptionFactory));
StringComparison.Ordinal,
(x, y, ct, exceptionFactory) => x.MustBe(y, ct, exceptionFactory));

[Fact]
public static void CustomMessage() =>
Expand All @@ -60,7 +61,8 @@ public static void CustomMessage() =>
public static void CustomExceptionIgnoreWhiteSpace() =>
Test.CustomException("Foo",
" foo",
(x, y, exceptionFactory) => x.MustBe(y, StringComparisonType.OrdinalIgnoreWhiteSpace, exceptionFactory));
StringComparisonType.OrdinalIgnoreWhiteSpace,
(x, y, ct, exceptionFactory) => x.MustBe(y, ct, exceptionFactory));

[Fact]
public static void CustomMessageIgnoreWhiteSpace() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static void CustomException() =>
public static void CustomExceptionIgnoreWhiteSpace() =>
Test.CustomException("Foo",
" Foo",
(x, y, exceptionFactory) => x.MustNotBe(y, StringComparisonType.OrdinalIgnoreWhiteSpace, exceptionFactory));
StringComparisonType.OrdinalIgnoreWhiteSpace,
(x, y, ct, exceptionFactory) => x.MustNotBe(y, ct, exceptionFactory));

[Fact]
public static void CustomMessage() =>
Expand Down
34 changes: 17 additions & 17 deletions Code/Light.GuardClauses/Check.StringAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <exception cref="Exception">Your custom exception thrown when <paramref name="parameter" /> is not equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? MustBe(this string? parameter, string? other, StringComparison comparisonType, Func<string?, string?, Exception> exceptionFactory)
public static string? MustBe(this string? parameter, string? other, StringComparison comparisonType, Func<string?, string?, StringComparison, Exception> exceptionFactory)
{
if (!string.Equals(parameter, other, comparisonType))
Throw.CustomException(exceptionFactory, parameter, other);
Throw.CustomException(exceptionFactory, parameter, other, comparisonType);
return parameter;
}

Expand All @@ -171,7 +171,7 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <param name="parameterName">The name of the parameter (optional).</param>
/// <param name="message">The message that will be passed to the resulting exception (optional).</param>
/// <exception cref="ValuesNotEqualException">Thrown when <paramref name="parameter" /> is not equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparisonType" /> enum.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? MustBe(this string? parameter, string? other, StringComparisonType comparisonType, [CallerArgumentExpression("parameter")] string? parameterName = null, string? message = null)
{
Expand All @@ -188,11 +188,11 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <param name="comparisonType">The enum value specifying how the two strings should be compared.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="other" /> are passed to this delegate.</param>
/// <exception cref="Exception">Your custom exception thrown when <paramref name="parameter" /> is not equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
public static string? MustBe(this string? parameter, string? other, StringComparisonType comparisonType, Func<string?, string?, Exception> exceptionFactory)
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparisonType" /> enum.</exception>
public static string? MustBe(this string? parameter, string? other, StringComparisonType comparisonType, Func<string?, string?, StringComparisonType, Exception> exceptionFactory)
{
if (!parameter.Equals(other, comparisonType))
Throw.CustomException(exceptionFactory, parameter, other);
Throw.CustomException(exceptionFactory, parameter, other, comparisonType);
return parameter;
}

Expand Down Expand Up @@ -220,7 +220,7 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <param name="parameter">The first string to be compared.</param>
/// <param name="other">The second string to be compared.</param>
/// <param name="comparisonType">The enum value specifying how the two strings should be compared.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="other" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="other" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">Your custom exception thrown when <paramref name="parameter" /> is equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -240,7 +240,7 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <param name="parameterName">The name of the parameter (optional).</param>
/// <param name="message">The message that will be passed to the resulting exception (optional).</param>
/// <exception cref="ValuesEqualException">Thrown when <paramref name="parameter" /> is equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparisonType" /> enum.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? MustNotBe(this string? parameter, string? other, StringComparisonType comparisonType, [CallerArgumentExpression("parameter")] string? parameterName = null, string? message = null)
{
Expand All @@ -255,14 +255,14 @@ public static string MustNotBeNullOrWhiteSpace([NotNull, ValidatedNotNull] this
/// <param name="parameter">The first string to be compared.</param>
/// <param name="other">The second string to be compared.</param>
/// <param name="comparisonType">The enum value specifying how the two strings should be compared.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="other" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="other" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">Your custom exception thrown when <paramref name="parameter" /> is equal to <paramref name="other" />.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparison" /> enum.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="comparisonType" /> is not a valid value from the <see cref="StringComparisonType" /> enum.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string? MustNotBe(this string? parameter, string? other, StringComparisonType comparisonType, Func<string?, string?, Exception> exceptionFactory)
public static string? MustNotBe(this string? parameter, string? other, StringComparisonType comparisonType, Func<string?, string?, StringComparisonType, Exception> exceptionFactory)
{
if (parameter.Equals(other, comparisonType))
Throw.CustomException(exceptionFactory, parameter, other);
Throw.CustomException(exceptionFactory, parameter, other, comparisonType);
return parameter;
}

Expand Down Expand Up @@ -441,7 +441,7 @@ public static string MustNotContain([NotNull, ValidatedNotNull] this string? par
/// </summary>
/// <param name="parameter">The string to be checked.</param>
/// <param name="value">The string that must not be part of <paramref name="parameter" />.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception (optional). <paramref name="parameter" /> and <paramref name="value" /> are passed to this </param>
/// <param name="exceptionFactory">The delegate that creates your custom exception (optional). <paramref name="parameter" /> and <paramref name="value" /> are passed to this delegate.</param>
/// <exception cref="Exception">
/// Your custom exception thrown when <paramref name="parameter" /> contains <paramref name="value" />,
/// or when <paramref name="parameter" /> is null,
Expand Down Expand Up @@ -693,7 +693,7 @@ public static string MustNotBeSubstringOf([NotNull, ValidatedNotNull] this strin
/// <param name="parameter">The string to be checked.</param>
/// <param name="value">The other string that must not contain <paramref name="parameter" />.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="value" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="value" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">
/// Your custom exception thrown when <paramref name="value" /> contains <paramref name="parameter" />,
/// or when <paramref name="parameter" /> is null,
Expand Down Expand Up @@ -771,7 +771,7 @@ public static string MustStartWith(
/// <param name="parameter">The string to be checked.</param>
/// <param name="value">The other string <paramref name="parameter"/> must start with.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="value" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="value" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">
/// Your custom exception thrown when <paramref name="parameter" /> does not start with <paramref name="value" />,
/// or when <paramref name="parameter" /> is null,
Expand Down Expand Up @@ -855,7 +855,7 @@ public static string MustNotStartWith(
/// <param name="parameter">The string to be checked.</param>
/// <param name="value">The other string that <paramref name="parameter" /> must not start with.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="value" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="value" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">
/// Your custom exception thrown when <paramref name="parameter" /> does not start with <paramref name="value" />,
/// or when <paramref name="parameter" /> is null,
Expand Down Expand Up @@ -938,7 +938,7 @@ public static string MustEndWith(
/// <param name="parameter">The string to be checked.</param>
/// <param name="value">The other string <paramref name="parameter"/> must end with.</param>
/// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" /> and <paramref name="value" /> are passed to this delegate.</param>
/// <param name="exceptionFactory">The delegate that creates your custom exception. <paramref name="parameter" />, <paramref name="value" />, and <paramref name="comparisonType" /> are passed to this delegate.</param>
/// <exception cref="Exception">
/// Your custom exception thrown when <paramref name="parameter" /> does not end with <paramref name="value" />,
/// or when <paramref name="parameter" /> is null,
Expand Down

0 comments on commit 8a53d51

Please sign in to comment.