< Summary

Information
Class: SwiftCollections.Diagnostics.SwiftThrowHelper
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/SwiftThrowHelper.cs
Line coverage
100%
Covered lines: 112
Uncovered lines: 0
Coverable lines: 112
Total lines: 507
Line coverage: 100%
Branch coverage
100%
Covered branches: 86
Total branches: 86
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/SwiftThrowHelper.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftThrowHelper.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8namespace SwiftCollections.Diagnostics;
 9
 10using System;
 11using System.Collections.Generic;
 12using System.Diagnostics.CodeAnalysis;
 13using System.Runtime.CompilerServices;
 14
 15/// <summary>
 16/// Provides allocation-conscious guard helpers for throwing common exceptions.
 17/// </summary>
 18/// <remarks>
 19/// Validation methods keep the success path small and route exception creation through no-inline throw helpers.
 20/// Interpolated custom messages are condition-gated so formatted expressions are not evaluated unless the guard throws.
 21/// </remarks>
 22public static class SwiftThrowHelper
 23{
 24    private static class GenericNullability<T>
 25    {
 726        internal static readonly bool CanBeNull = default(T) is null;
 27    }
 28
 29    #region Null Argument Validation
 30
 31    /// <summary>
 32    /// Throws an <see cref="ArgumentNullException"/> if the provided argument is null.
 33    /// </summary>
 34    /// <param name="argument">The argument to check for null.</param>
 35    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 36    /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
 37    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 38    public static void ThrowIfNull(
 39        [NotNull] object? argument,
 40        [CallerArgumentExpression(nameof(argument))] string? paramName = null)
 41    {
 21310342        if (argument is null)
 3343            ThrowArgumentNullException(paramName);
 21307044    }
 45
 46    /// <summary>
 47    /// Throws an <see cref="ArgumentNullException"/> if the provided generic argument is null.
 48    /// </summary>
 49    /// <typeparam name="T">The type of the argument to check.</typeparam>
 50    /// <param name="argument">The argument to check for null.</param>
 51    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 52    /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
 53#pragma warning disable CS8777 // Cached generic nullability avoids boxing non-nullable value types.
 54    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 55    public static void ThrowIfNullGeneric<T>(
 56        [NotNull] T argument,
 57        [CallerArgumentExpression(nameof(argument))] string? paramName = null)
 58    {
 34208359        if (GenericNullability<T>.CanBeNull && argument is null)
 660            ThrowArgumentNullException(paramName);
 34207761    }
 62#pragma warning restore CS8777
 63
 64    /// <summary>
 65    /// Throws an <see cref="ArgumentNullException"/> if the specified value is null and nulls are not legal for <typepa
 66    /// </summary>
 67    /// <typeparam name="TValue">The value type used to determine whether null is legal.</typeparam>
 68    /// <param name="value">The value to check.</param>
 69    /// <param name="defaultValue">A default value of type <typeparamref name="TValue"/> used to determine if nulls are 
 70    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 71    /// <exception cref="ArgumentNullException">Thrown when the value is null and nulls are illegal.</exception>
 72    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 73    public static void ThrowIfNullAndNullsAreIllegal<TValue>(
 74        object? value,
 75        TValue? defaultValue,
 76        [CallerArgumentExpression(nameof(value))] string? paramName = null)
 77    {
 1578        if (value is null && defaultValue is not null)
 179            ThrowArgumentNullException(paramName);
 1480    }
 81
 82    [DoesNotReturn]
 83    [MethodImpl(MethodImplOptions.NoInlining)]
 84    private static void ThrowArgumentNullException(string? paramName)
 85    {
 4086        paramName = NormalizeParamName(paramName);
 87
 4088        if (string.IsNullOrEmpty(paramName))
 189            throw new ArgumentNullException(null, "Value cannot be null.");
 90
 3991        throw new ArgumentNullException(paramName);
 92    }
 93
 94    #endregion
 95
 96    #region Out of Range Validation
 97
 98    /// <summary>
 99    /// Throws an <see cref="ArgumentOutOfRangeException"/> if the specified value is negative.
 100    /// </summary>
 101    /// <param name="value">The value to check.</param>
 102    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 103    /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is negative.</exception>
 104    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 105    public static void ThrowIfNegative(
 106        int value,
 107        [CallerArgumentExpression(nameof(value))] string? paramName = null) =>
 363108        _ = value < 0 && ThrowArgumentOutOfRangeException(
 363109            NormalizeParamName(paramName),
 363110            value,
 363111            GetNonNegativeMessage(NormalizeParamName(paramName)));
 112
 113    /// <summary>
 114    /// Throws an <see cref="ArgumentOutOfRangeException"/> if the specified value is negative or zero.
 115    /// </summary>
 116    /// <param name="value">The value to check.</param>
 117    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 118    /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is negative or zero.</exception>
 119    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 120    public static void ThrowIfNegativeOrZero(
 121        int value,
 122        [CallerArgumentExpression(nameof(value))] string? paramName = null) =>
 104123        _ = value <= 0 && ThrowArgumentOutOfRangeException(
 104124            NormalizeParamName(paramName),
 104125            value,
 104126            GetPositiveMessage(NormalizeParamName(paramName)));
 127
 128    /// <summary>
 129    /// Throws an <see cref="ArgumentOutOfRangeException"/> if the specified condition is true.
 130    /// </summary>
 131    /// <param name="condition">The condition to evaluate.</param>
 132    /// <param name="actualValue">The value that caused the exception.</param>
 133    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 134    /// <param name="message">An optional message to include in the exception.</param>
 135    /// <exception cref="ArgumentOutOfRangeException">Thrown when the condition is true.</exception>
 136    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 137    public static void ThrowIfArgumentOutOfRange(
 138        [DoesNotReturnIf(true)] bool condition,
 139        int? actualValue,
 140        [CallerArgumentExpression(nameof(actualValue))] string? paramName = null,
 141        string? message = null) =>
 175142        _ = condition && ThrowArgumentOutOfRangeException(
 175143            NormalizeParamName(paramName),
 175144            actualValue,
 175145            message ?? GetArgumentOutOfRangeMessage(NormalizeParamName(paramName)));
 146
 147    /// <summary>
 148    /// Throws an <see cref="ArgumentOutOfRangeException"/> with a lazily formatted message if the specified condition i
 149    /// </summary>
 150    /// <param name="condition">The condition to evaluate.</param>
 151    /// <param name="actualValue">The value that caused the exception.</param>
 152    /// <param name="message">The interpolated exception message.</param>
 153    /// <exception cref="ArgumentOutOfRangeException">Thrown when the condition is true.</exception>
 154    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 155    public static void ThrowIfArgumentOutOfRange(
 156        [DoesNotReturnIf(true)] bool condition,
 157        int? actualValue,
 158        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 159    {
 2160        if (condition)
 1161            ThrowArgumentOutOfRangeException(null, actualValue, message.GetFormattedText());
 1162    }
 163
 164    /// <summary>
 165    /// Throws an <see cref="ArgumentOutOfRangeException"/> with a lazily formatted message if the specified condition i
 166    /// </summary>
 167    /// <param name="condition">The condition to evaluate.</param>
 168    /// <param name="actualValue">The value that caused the exception.</param>
 169    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 170    /// <param name="message">The interpolated exception message.</param>
 171    /// <exception cref="ArgumentOutOfRangeException">Thrown when the condition is true.</exception>
 172    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 173    public static void ThrowIfArgumentOutOfRange(
 174        [DoesNotReturnIf(true)] bool condition,
 175        int? actualValue,
 176        string? paramName,
 177        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message) =>
 2178        _ = condition && ThrowArgumentOutOfRangeException(
 2179            NormalizeParamName(paramName),
 2180            actualValue,
 2181            message.GetFormattedText());
 182
 183    /// <summary>
 184    /// Throws an <see cref="ArgumentOutOfRangeException"/> if a copy destination index is outside [0, length].
 185    /// </summary>
 186    /// <param name="index">The destination index to check.</param>
 187    /// <param name="length">The destination length.</param>
 188    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 189    /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is outside [0, length].</exception>
 190    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 191    public static void ThrowIfArrayIndexInvalid(
 192        int index,
 193        int length,
 194        [CallerArgumentExpression(nameof(index))] string? paramName = null) =>
 194195        _ = (uint)index > (uint)length && ThrowArgumentOutOfRangeException(
 194196            NormalizeParamName(paramName),
 194197            index,
 194198            "Array index is out of range.");
 199
 200    [DoesNotReturn]
 201    [MethodImpl(MethodImplOptions.NoInlining)]
 202    private static bool ThrowArgumentOutOfRangeException(string? paramName, object? actualValue, string message) =>
 22203        throw new ArgumentOutOfRangeException(paramName, actualValue, message);
 204
 205    #endregion
 206
 207    #region Invalid State Validation
 208
 209    /// <summary>
 210    /// Throws an <see cref="ArgumentException"/> if the specified condition is true.
 211    /// </summary>
 212    /// <param name="condition">The condition to evaluate.</param>
 213    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 214    /// <param name="message">An optional message to include in the exception.</param>
 215    /// <exception cref="ArgumentException">Thrown when the condition is true.</exception>
 216    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 217    public static void ThrowIfArgument(
 218        [DoesNotReturnIf(true)] bool condition,
 219        string? paramName = null,
 220        string? message = null) =>
 226221        _ = condition && ThrowArgumentException(
 226222            NormalizeParamName(paramName),
 226223            message ?? GetArgumentMessage(NormalizeParamName(paramName)));
 224
 225    /// <summary>
 226    /// Throws an <see cref="ArgumentException"/> with a lazily formatted message if the specified condition is true.
 227    /// </summary>
 228    /// <param name="condition">The condition to evaluate.</param>
 229    /// <param name="message">The interpolated exception message.</param>
 230    /// <exception cref="ArgumentException">Thrown when the condition is true.</exception>
 231    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 232    public static void ThrowIfArgument(
 233        [DoesNotReturnIf(true)] bool condition,
 234        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 235    {
 2236        if (condition)
 1237            ThrowArgumentException(null, message.GetFormattedText());
 1238    }
 239
 240    /// <summary>
 241    /// Throws an <see cref="ArgumentException"/> with a lazily formatted message if the specified condition is true.
 242    /// </summary>
 243    /// <param name="condition">The condition to evaluate.</param>
 244    /// <param name="paramName">The name of the parameter that caused the exception.</param>
 245    /// <param name="message">The interpolated exception message.</param>
 246    /// <exception cref="ArgumentException">Thrown when the condition is true.</exception>
 247    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 248    public static void ThrowIfArgument(
 249        [DoesNotReturnIf(true)] bool condition,
 250        string? paramName,
 251        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message) =>
 2252        _ = condition && ThrowArgumentException(
 2253            NormalizeParamName(paramName),
 2254            message.GetFormattedText());
 255
 256    [DoesNotReturn]
 257    [MethodImpl(MethodImplOptions.NoInlining)]
 258    private static bool ThrowArgumentException(string? paramName, string message) =>
 35259        throw new ArgumentException(message, paramName);
 260
 261    /// <summary>
 262    /// Throws an <see cref="InvalidOperationException"/> if the specified condition is true.
 263    /// </summary>
 264    /// <param name="condition">The condition to evaluate.</param>
 265    /// <param name="objectName">The name of the object in an invalid state.</param>
 266    /// <param name="message">An optional message to include in the exception.</param>
 267    /// <exception cref="InvalidOperationException">Thrown when the condition is true.</exception>
 268    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 269    public static void ThrowIfTrue(
 270        [DoesNotReturnIf(true)] bool condition,
 271        string? objectName = null,
 272        string? message = null)
 273    {
 1953274        if (condition)
 39275            ThrowInvalidOperationException(message ?? GetInvalidOperationMessage(objectName));
 1914276    }
 277
 278    /// <summary>
 279    /// Throws an <see cref="InvalidOperationException"/> with a lazily formatted message if the specified condition is 
 280    /// </summary>
 281    /// <param name="condition">The condition to evaluate.</param>
 282    /// <param name="message">The interpolated exception message.</param>
 283    /// <exception cref="InvalidOperationException">Thrown when the condition is true.</exception>
 284    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 285    public static void ThrowIfTrue(
 286        [DoesNotReturnIf(true)] bool condition,
 287        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 288    {
 2289        if (condition)
 1290            ThrowInvalidOperationException(message.GetFormattedText());
 1291    }
 292
 293    /// <summary>
 294    /// Throws an <see cref="InvalidOperationException"/> with a lazily formatted message if the specified condition is 
 295    /// </summary>
 296    /// <param name="condition">The condition to evaluate.</param>
 297    /// <param name="objectName">The name of the object in an invalid state.</param>
 298    /// <param name="message">The interpolated exception message.</param>
 299    /// <exception cref="InvalidOperationException">Thrown when the condition is true.</exception>
 300    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 301    public static void ThrowIfTrue(
 302        [DoesNotReturnIf(true)] bool condition,
 303        string? objectName,
 304        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 305    {
 2306        if (condition)
 1307            ThrowInvalidOperationException(message.GetFormattedText());
 1308    }
 309
 310    [DoesNotReturn]
 311    [MethodImpl(MethodImplOptions.NoInlining)]
 312    private static void ThrowInvalidOperationException(string message) =>
 41313        throw new InvalidOperationException(message);
 314
 315    /// <summary>
 316    /// Throws an <see cref="ObjectDisposedException"/> if the specified condition is true.
 317    /// </summary>
 318    /// <param name="condition">The condition to evaluate.</param>
 319    /// <param name="objectName">The name of the object that has been disposed.</param>
 320    /// <param name="message">An optional message to include in the exception.</param>
 321    /// <exception cref="ObjectDisposedException">Thrown when the condition is true.</exception>
 322    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 323    public static void ThrowIfDisposed(
 324        [DoesNotReturnIf(true)] bool condition,
 325        string? objectName = null,
 326        string? message = null)
 327    {
 237328        if (condition)
 22329            ThrowObjectDisposedException(objectName, message ?? GetObjectDisposedMessage(objectName));
 215330    }
 331
 332    /// <summary>
 333    /// Throws an <see cref="ObjectDisposedException"/> with a lazily formatted message if the specified condition is tr
 334    /// </summary>
 335    /// <param name="condition">The condition to evaluate.</param>
 336    /// <param name="message">The interpolated exception message.</param>
 337    /// <exception cref="ObjectDisposedException">Thrown when the condition is true.</exception>
 338    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 339    public static void ThrowIfDisposed(
 340        [DoesNotReturnIf(true)] bool condition,
 341        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 342    {
 2343        if (condition)
 1344            ThrowObjectDisposedException(null, message.GetFormattedText());
 1345    }
 346
 347    /// <summary>
 348    /// Throws an <see cref="ObjectDisposedException"/> with a lazily formatted message if the specified condition is tr
 349    /// </summary>
 350    /// <param name="condition">The condition to evaluate.</param>
 351    /// <param name="objectName">The name of the object that has been disposed.</param>
 352    /// <param name="message">The interpolated exception message.</param>
 353    /// <exception cref="ObjectDisposedException">Thrown when the condition is true.</exception>
 354    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 355    public static void ThrowIfDisposed(
 356        [DoesNotReturnIf(true)] bool condition,
 357        string? objectName,
 358        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 359    {
 2360        if (condition)
 1361            ThrowObjectDisposedException(objectName, message.GetFormattedText());
 1362    }
 363
 364    [DoesNotReturn]
 365    [MethodImpl(MethodImplOptions.NoInlining)]
 366    private static void ThrowObjectDisposedException(string? objectName, string message) =>
 24367        throw new ObjectDisposedException(objectName, message);
 368
 369    /// <summary>
 370    /// Throws a <see cref="KeyNotFoundException"/> if the specified index is negative.
 371    /// </summary>
 372    /// <param name="index">The index to check.</param>
 373    /// <param name="key">The key associated with the index.</param>
 374    /// <exception cref="KeyNotFoundException">Thrown when the index is negative.</exception>
 375    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 376    public static void ThrowIfKeyInvalid(int index, object? key = null)
 377    {
 4354378        if (index < 0)
 3379            ThrowKeyNotFoundException(GetKeyNotFoundMessage(key));
 4351380    }
 381
 382    /// <summary>
 383    /// Throws a <see cref="KeyNotFoundException"/> if the specified condition is true.
 384    /// </summary>
 385    /// <param name="condition">The condition to evaluate.</param>
 386    /// <param name="key">The key associated with the lookup.</param>
 387    /// <param name="message">An optional message to include in the exception.</param>
 388    /// <exception cref="KeyNotFoundException">Thrown when the condition is true.</exception>
 389    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 390    public static void ThrowIfKeyNotFound(
 391        [DoesNotReturnIf(true)] bool condition,
 392        object? key = null,
 393        string? message = null)
 394    {
 48395        if (condition)
 5396            ThrowKeyNotFoundException(message ?? GetKeyNotFoundMessage(key));
 43397    }
 398
 399    /// <summary>
 400    /// Throws a <see cref="KeyNotFoundException"/> with a lazily formatted message if the specified condition is true.
 401    /// </summary>
 402    /// <param name="condition">The condition to evaluate.</param>
 403    /// <param name="message">The interpolated exception message.</param>
 404    /// <exception cref="KeyNotFoundException">Thrown when the condition is true.</exception>
 405    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 406    public static void ThrowIfKeyNotFound(
 407        [DoesNotReturnIf(true)] bool condition,
 408        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 409    {
 2410        if (condition)
 1411            ThrowKeyNotFoundException(message.GetFormattedText());
 1412    }
 413
 414    /// <summary>
 415    /// Throws a <see cref="KeyNotFoundException"/> with a lazily formatted message if the specified condition is true.
 416    /// </summary>
 417    /// <param name="condition">The condition to evaluate.</param>
 418    /// <param name="key">The key associated with the lookup.</param>
 419    /// <param name="message">The interpolated exception message.</param>
 420    /// <exception cref="KeyNotFoundException">Thrown when the condition is true.</exception>
 421    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 422    public static void ThrowIfKeyNotFound(
 423        [DoesNotReturnIf(true)] bool condition,
 424        object? key,
 425        [InterpolatedStringHandlerArgument(nameof(condition))] SwiftThrowInterpolatedStringHandler message)
 426    {
 2427        if (condition)
 1428            ThrowKeyNotFoundException(message.GetFormattedText());
 1429    }
 430
 431    [DoesNotReturn]
 432    [MethodImpl(MethodImplOptions.NoInlining)]
 433    private static void ThrowKeyNotFoundException(string message) =>
 10434        throw new KeyNotFoundException(message);
 435
 436    /// <summary>
 437    /// Throws an <see cref="IndexOutOfRangeException"/> if the specified index is outside the valid range defined by co
 438    /// </summary>
 439    /// <param name="index">The index to check.</param>
 440    /// <param name="count">The total number of elements in the collection.</param>
 441    /// <exception cref="IndexOutOfRangeException">Thrown when the index is outside the valid range.</exception>
 442    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 443    public static void ThrowIfListIndexInvalid(
 444        int index,
 445        int count)
 446    {
 8244447        if ((uint)index >= (uint)count)
 11448            ThrowIndexOutOfRangeException(index);
 8233449    }
 450
 451    [DoesNotReturn]
 452    [MethodImpl(MethodImplOptions.NoInlining)]
 453    private static void ThrowIndexOutOfRangeException(int value) =>
 11454        throw new IndexOutOfRangeException($"Index out of range: {value}");
 455
 456    #endregion
 457
 458    #region Message Helpers
 459
 460    private static string GetNonNegativeMessage(string? paramName) =>
 5461        string.IsNullOrEmpty(paramName)
 5462            ? "Value must be non-negative."
 5463            : $"{paramName} must be non-negative.";
 464
 465    private static string GetPositiveMessage(string? paramName) =>
 3466        string.IsNullOrEmpty(paramName)
 3467            ? "Value must be greater than zero."
 3468            : $"{paramName} must be greater than zero.";
 469
 470    private static string GetArgumentOutOfRangeMessage(string? paramName) =>
 3471        string.IsNullOrEmpty(paramName)
 3472            ? "Specified argument was out of range."
 3473            : $"{paramName} is out of range.";
 474
 475    private static string GetArgumentMessage(string? paramName) =>
 2476        string.IsNullOrEmpty(paramName)
 2477            ? "The argument is invalid."
 2478            : $"{paramName} is invalid.";
 479
 480    private static string GetInvalidOperationMessage(string? objectName) =>
 2481        string.IsNullOrEmpty(objectName)
 2482            ? "Operation is not valid in the current state."
 2483            : $"Object '{objectName}' is in an invalid state.";
 484
 485    private static string GetObjectDisposedMessage(string? objectName) =>
 21486        string.IsNullOrEmpty(objectName)
 21487            ? "Object has been disposed."
 21488            : $"Object '{objectName}' has been disposed.";
 489
 490    private static string GetKeyNotFoundMessage(object? key) =>
 7491        key is null
 7492            ? "Key was not found."
 7493            : $"Key not found: {key}";
 494
 495    private static string? NormalizeParamName(string? paramName)
 496    {
 108497        if (string.IsNullOrEmpty(paramName) || paramName == "null")
 8498            return null;
 499
 100500        char first = paramName[0];
 100501        return char.IsLetter(first) || first == '_' || first == '@'
 100502            ? paramName
 100503            : null;
 504    }
 505
 506    #endregion
 507}

Methods/Properties

.cctor()
ThrowIfNull(System.Object,System.String)
ThrowIfNullGeneric(T,System.String)
ThrowIfNullAndNullsAreIllegal(System.Object,TValue,System.String)
ThrowArgumentNullException(System.String)
ThrowIfNegative(System.Int32,System.String)
ThrowIfNegativeOrZero(System.Int32,System.String)
ThrowIfArgumentOutOfRange(System.Boolean,System.Nullable`1<System.Int32>,System.String,System.String)
ThrowIfArgumentOutOfRange(System.Boolean,System.Nullable`1<System.Int32>,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfArgumentOutOfRange(System.Boolean,System.Nullable`1<System.Int32>,System.String,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfArrayIndexInvalid(System.Int32,System.Int32,System.String)
ThrowArgumentOutOfRangeException(System.String,System.Object,System.String)
ThrowIfArgument(System.Boolean,System.String,System.String)
ThrowIfArgument(System.Boolean,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfArgument(System.Boolean,System.String,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowArgumentException(System.String,System.String)
ThrowIfTrue(System.Boolean,System.String,System.String)
ThrowIfTrue(System.Boolean,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfTrue(System.Boolean,System.String,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowInvalidOperationException(System.String)
ThrowIfDisposed(System.Boolean,System.String,System.String)
ThrowIfDisposed(System.Boolean,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfDisposed(System.Boolean,System.String,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowObjectDisposedException(System.String,System.String)
ThrowIfKeyInvalid(System.Int32,System.Object)
ThrowIfKeyNotFound(System.Boolean,System.Object,System.String)
ThrowIfKeyNotFound(System.Boolean,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowIfKeyNotFound(System.Boolean,System.Object,SwiftCollections.Diagnostics.SwiftThrowInterpolatedStringHandler)
ThrowKeyNotFoundException(System.String)
ThrowIfListIndexInvalid(System.Int32,System.Int32)
ThrowIndexOutOfRangeException(System.Int32)
GetNonNegativeMessage(System.String)
GetPositiveMessage(System.String)
GetArgumentOutOfRangeMessage(System.String)
GetArgumentMessage(System.String)
GetInvalidOperationMessage(System.String)
GetObjectDisposedMessage(System.String)
GetKeyNotFoundMessage(System.Object)
NormalizeParamName(System.String)