Verify Args
Three code snippets for Visual Studio 2012 & 2013. It is used by Surviveplus.net developers team for Validating Arguments.
- Throw Exception when argument is the empty string or a null reference [nullempex]
- Throw Exception when argument is a null reference [nullex]
- Throw Exception when argument is white-space, the empty string or a null reference [nullwex]
Inserting codes in C# (Movie)
Description
In Visual Studio Static Code Analysis, all reference arguments that are passed to externally visible methods should be checked against null.
CA1062: Validate arguments of public methods
Use these snippets, to insert validation logic easily.
[su_tabs]
[su_tab title=”C#”]
Throw Exception when argument is the empty string or a null reference [nullempex]
if (value == null) throw new ArgumentNullException("value");
Throw Exception when argument is a null reference [nullex]
if (string.IsNullOrEmpty(value)) throw new ArgumentException("Cannot provide the empty string or a null reference (Nothing in Visual Basic) to value.", "value");
Throw Exception when argument is white-space, the empty string or a null reference [nullwex]
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Cannot provide white-space characters, the empty string or a null reference (Nothing in Visual Basic) to value.", "value");
[/su_tab]
[su_tab title=”Visual Basic”]
Throw Exception when argument is the empty string or a null reference [nullempex]
If value Is Nothing Then Throw New ArgumentNullException("value")
Throw Exception when argument is a null reference [nullex]
If String.IsNullOrEmpty(value) Then Throw New ArgumentException("Cannot provide the empty string or Nothing (a null reference in C#) to value.", "value")
Throw Exception when argument is white-space, the empty string or a null reference [nullwex]
If String.IsNullOrWhiteSpace(value) Then Throw New ArgumentException("Cannot provide white-space characters, the empty string or Nothing (a null reference in C#) to value.", "value")
[/su_tab]
[/su_tabs]




