O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Argument Validation

The book sample code commonly uses a custom ArgumentValidator class to ensure that method arguments are not null or fall within a valid range. This allows a method to fail fast, rather than continuing and raising a more difficult to diagnose error.

You frequently see statements like the following at the beginning of a method:

string PerformSomeAction(string value){    stringField = ArgumentValidator.AssertNotNull(value, "value");...}

Here, if value is null, then an ArgumentNullException is thrown. If not null, then the stringField field is set to the value in a fluent manner.

Note

Microsoft has a far more feature rich argument validation tool called Code Contracts, which integrates into Visual ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required