Skip to content

Modernize and streamline argument checks #120

@flobernd

Description

@flobernd

Proposal

  1. Create a new internal Verify class that makes use of modern features like e.g. the [CallerArgumentExpression] attribute.
  2. Replace all existing argument checks.

Intention

Removes boilerplate code by instructing the compiler to automatically pass argument expressions to the check function.

Improves quality of exception messages.

Example

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  internal static void NotNull([NotNull] object? obj, [CallerArgumentExpression(nameof(obj))] string? paramName = null)
  {
#if NET
      ArgumentNullException.ThrowIfNull(obj, paramName);
#else
      if (obj is null)
      {
          throw new ArgumentNullException(paramName);
      }
#endif
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions