Skip to content

Instantly share code, notes, and snippets.

@ntxinh
Last active June 21, 2020 14:41
Show Gist options
  • Save ntxinh/511d341ffd327f0b343c89975f193063 to your computer and use it in GitHub Desktop.
Save ntxinh/511d341ffd327f0b343c89975f193063 to your computer and use it in GitHub Desktop.
parameter null validation
// https://dev.to/callmewhy/yo-yo-check-null-320m
// replace == null with is null because the == operator can be overloaded.
internal static class ThrowIf
{
public static class Argument
{
public static void IsNull<T>(T argument)
{
if (argument is null)
{
throw new ArgumentNullException(typeof(T).Name);
}
}
}
}
public void DoSomething(Foo foo)
{
ThrowIf.Argument.IsNull(foo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment