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.
Throw Exception when argument is the empty string or a null reference [nullempex]
1 |
if (value == null) throw new ArgumentNullException("value"); |
Throw Exception when argument is a null reference [nullex]
1 |
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]
1 |
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"); |
Throw Exception when argument is the empty string or a null reference [nullempex]
1 |
If value Is Nothing Then Throw New ArgumentNullException("value") |
Throw Exception when argument is a null reference [nullex]
1 |
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]
1 |
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") |