Argument validation

Topics: C# Language Design
Nov 15, 2014 at 8:03 PM
Quite often in the code we do argument validation with plenty of if..throw code. For example:
void Execute(string name)
    if (string.IsNullOrWhiteSpace(name))
        throw new ArgumentNullException("name");
Is there any plan to add a new set of keywords applied to arguments only. For example:
void Execute(required string name)
void Execute(nonempty string name)
void Execute(negative int value)

Nov 15, 2014 at 10:37 PM
I doubt you'll see dedicated keywords for validation. The number of scenarios could explode resulting in a lot of new keywords. Rather I think for now you'll see support for code contracts and eventually if the subject of metaprogramming is tackled you'll probably see validation enforced by parameter-targeting attributes.