forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFxCop.Design.ValidateArguments.vb
61 lines (44 loc) · 1.35 KB
/
FxCop.Design.ValidateArguments.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'<Snippet1>
Namespace DesignLibrary
Public Class Test
' This method violates the rule.
Sub DoNotValidate(ByVal input As String)
If input.Length <> 0 Then
Console.WriteLine(input)
End If
End Sub
' This method satisfies the rule.
Sub Validate(ByVal input As String)
If input Is Nothing Then
Throw New ArgumentNullException("input")
End If
If input.Length <> 0 Then
Console.WriteLine(input)
End If
End Sub
End Class
End Namespace
'</Snippet1>
Public Class SnippetClass
'<Snippet2>
Public Function Method(ByVal value As String) As String
EnsureNotNull(value)
' Fires incorrectly
Return value.ToString()
End Function
Private Sub EnsureNotNull(ByVal value As String)
If value Is Nothing Then
Throw (New ArgumentNullException("value"))
End If
End Sub
'</Snippet2>
'<Snippet3>
Public Function Method(ByVal value1 As String, ByVal value2 As String) As String
If value1 Is Nothing OrElse value2 Is Nothing Then
Throw New ArgumentNullException()
End If
' Fires incorrectly
Return value1.ToString() + value2.ToString()
End Function
'</Snippet3>
End Class