Skip to content

Commit

Permalink
use nameof for CallerArgumentExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi authored Oct 23, 2024
1 parent e54b226 commit e53cd0d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Shared/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static class Guard
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNull([NotNull] object? value, [CallerArgumentExpression("value")] string? paramName = null)
public static void ThrowIfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value is null)
{
Expand All @@ -74,7 +74,7 @@ public static void ThrowIfNull([NotNull] object? value, [CallerArgumentExpressio
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentExpression("value")] string? paramName = null)
public static void ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
{
if (string.IsNullOrEmpty(value))
Expand All @@ -91,7 +91,7 @@ public static void ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentEx
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression("value")] string? paramName = null)
public static void ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.
{
if (string.IsNullOrWhiteSpace(value))
Expand All @@ -109,7 +109,7 @@ public static void ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgum
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression("value")] string? paramName = null)
public static void ThrowIfZero(int value, string message = "Must not be zero", [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value == 0)
{
Expand All @@ -124,7 +124,7 @@ public static void ThrowIfZero(int value, string message = "Must not be zero", [
/// <param name="paramName">The parameter name to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("value")] string? paramName = null)
public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
ThrowIfOutOfRange(value, paramName, min: Timeout.Infinite, message: $"Must be non-negative or '{nameof(Timeout)}.{nameof(Timeout.Infinite)}'");
}
Expand All @@ -141,7 +141,7 @@ public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression("v
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value")] string? paramName = null, int min = int.MinValue, int max = int.MaxValue, string? minName = null, string? maxName = null, string? message = null)
public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression(nameof(value))] string? paramName = null, int min = int.MinValue, int max = int.MaxValue, string? minName = null, string? maxName = null, string? message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -158,7 +158,7 @@ public static void ThrowIfOutOfRange(int value, [CallerArgumentExpression("value
/// <param name="message">An optional custom message to use in the thrown exception.</param>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("value")] string? paramName = null, double min = double.MinValue, double max = double.MaxValue, string? minName = null, string? maxName = null, string? message = null)
public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression(nameof(value))] string? paramName = null, double min = double.MinValue, double max = double.MaxValue, string? minName = null, string? maxName = null, string? message = null)
{
Range(value, paramName, min, max, minName, maxName, message);
}
Expand All @@ -172,7 +172,7 @@ public static void ThrowIfOutOfRange(double value, [CallerArgumentExpression("va
/// <returns>The value casted to the specified type.</returns>
[DebuggerHidden]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ThrowIfNotOfType<T>([NotNull] object? value, [CallerArgumentExpression("value")] string? paramName = null)
public static T ThrowIfNotOfType<T>([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value is not T result)
{
Expand Down

0 comments on commit e53cd0d

Please sign in to comment.