Exploring the .NET CoreFX Part 4: The Requires Convenience Class

This is part 4 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
    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)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s