Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize and streamline argument checks #120

Open
flobernd opened this issue Oct 11, 2024 · 0 comments
Open

Modernize and streamline argument checks #120

flobernd opened this issue Oct 11, 2024 · 0 comments

Comments

@flobernd
Copy link
Member

flobernd commented Oct 11, 2024

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
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant