Published: 2014-11-20
This is part 4/17 of my Exploring the .NET CoreFX series.
The System.Collections.Immutable project in the .NET CoreFX includes a convenience class called Requires, which looks like:
internal static class Requires
{
[DebuggerStepThrough]
public static T NotNull([ValidatedNotNull]T value, string parameterName)
where T : class // ensures value-types aren't passed to a null checking method
{
if (value == null)
{
throw new ArgumentNullException(parameterName);
}
return value;
}
...
}
This allows other methods to write code like:
public void Foo(string bar)
{
Requires.NotNull(bar);
...
}