Last active
June 21, 2020 14:41
-
-
Save ntxinh/511d341ffd327f0b343c89975f193063 to your computer and use it in GitHub Desktop.
parameter null validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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