Skip to content

Instantly share code, notes, and snippets.

@rstropek
Created June 6, 2021 13:27
Show Gist options
  • Save rstropek/e883d7590ad7f2cc5e7c679fdabe51c4 to your computer and use it in GitHub Desktop.
Save rstropek/e883d7590ad7f2cc5e7c679fdabe51c4 to your computer and use it in GitHub Desktop.
#nullable enable
using System;
using System.Runtime.CompilerServices;
var x = 5;
Verify.Lower(x * 2, Convert.ToInt32(Math.Floor(Math.PI)));
public static class Verify
{
public static void Lower(int argument, int maxValue,
[CallerArgumentExpression("argument")] string? argumentExpression = null,
[CallerArgumentExpression("maxValue")] string? maxValueExpression = null)
{
if (argument > maxValue)
{
throw new ArgumentOutOfRangeException(nameof(argument),
$"{argumentExpression} must be lower or equal {maxValueExpression}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment