You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Microsoft.VisualStudio.Validation/Requires.cs
+31-30Lines changed: 31 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@
8
8
usingSystem.Globalization;
9
9
usingSystem.Resources;
10
10
usingSystem.Runtime;
11
+
usingSystem.Runtime.CompilerServices;
11
12
12
13
namespaceMicrosoft;
13
14
@@ -21,12 +22,12 @@ public static class Requires
21
22
/// </summary>
22
23
/// <typeparam name="T">The type of the parameter.</typeparam>
23
24
/// <param name="value">The value of the argument.</param>
24
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
25
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
25
26
/// <returns>The value of the parameter.</returns>
26
27
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
27
28
[DebuggerStepThrough]
28
29
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
whereT:class// ensures value-types aren't passed to a null checking method
31
32
{
32
33
if(valueisnull)
@@ -41,12 +42,12 @@ public static T NotNull<T>([ValidatedNotNull, NotNull] T value, string? paramete
41
42
/// Throws an exception if the specified parameter's value is IntPtr.Zero.
42
43
/// </summary>
43
44
/// <param name="value">The value of the argument.</param>
44
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
45
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
45
46
/// <returns>The value of the parameter.</returns>
46
47
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see cref="IntPtr.Zero"/>.</exception>
47
48
[DebuggerStepThrough]
48
49
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
/// Throws an exception if the specified parameter's value is null.
61
62
/// </summary>
62
63
/// <param name="value">The value of the argument.</param>
63
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
64
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
64
65
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
65
66
/// <remarks>
66
67
/// This method allows async methods to use Requires.NotNull without having to assign the result
67
68
/// to local variables to avoid C# warnings.
68
69
/// </remarks>
69
70
[DebuggerStepThrough]
70
71
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
/// <typeparam name="T">The type of the return value of the task.</typeparam>
83
84
/// <param name="value">The value of the argument.</param>
84
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
85
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
85
86
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
86
87
/// <remarks>
87
88
/// This method allows async methods to use Requires.NotNull without having to assign the result
88
89
/// to local variables to avoid C# warnings.
89
90
/// </remarks>
90
91
[DebuggerStepThrough]
91
92
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
/// <typeparam name="T">The type of the parameter.</typeparam>
104
105
/// <param name="value">The value of the argument.</param>
105
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
106
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
106
107
/// <returns>The value of the parameter.</returns>
107
108
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
108
109
/// <remarks>
109
110
/// This method exists for callers who themselves only know the type as a generic parameter which
110
111
/// may or may not be a class, but certainly cannot be null.
@@ -124,10 +125,10 @@ public static T NotNullAllowStructs<T>([ValidatedNotNull, NotNull] T value, stri
124
125
/// Throws an exception if the specified parameter's value is null or empty.
125
126
/// </summary>
126
127
/// <param name="value">The value of the argument.</param>
127
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
128
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
128
129
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="null"/> or empty.</exception>
/// Throws an exception if the specified parameter's value is null, empty, or whitespace.
148
149
/// </summary>
149
150
/// <param name="value">The value of the argument.</param>
150
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
151
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
151
152
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="null"/> or empty.</exception>
/// <param name="values">The value of the argument.</param>
179
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
180
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
180
181
/// <exception cref="ArgumentException">Thrown if the tested condition is false.</exception>
/// <typeparam name="T">The type produced by the enumeration.</typeparam>
207
208
/// <param name="values">The value of the argument.</param>
208
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
209
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
209
210
/// <exception cref="ArgumentException">Thrown if the tested condition is false.</exception>
// Consider the performance when changing the code to delegate to NotNull.
@@ -245,10 +246,10 @@ public static void NotNullOrEmpty<T>([ValidatedNotNull, NotNull] IEnumerable<T>
245
246
/// </summary>
246
247
/// <typeparam name="T">The type of value in the collection.</typeparam>
247
248
/// <param name="values">The value of the argument.</param>
248
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
249
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
249
250
/// <exception cref="ArgumentException">Thrown if the tested condition is false.</exception>
// Consider the performance when changing the code to delegate to NotNull.
@@ -270,10 +271,10 @@ public static void NotNullOrEmpty<T>([ValidatedNotNull, NotNull] ICollection<T>
270
271
/// </summary>
271
272
/// <typeparam name="T">The type of the elements in the sequence.</typeparam>
272
273
/// <param name="values">The value of the argument.</param>
273
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
274
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
274
275
/// <exception cref="ArgumentException">Thrown if the tested condition is false.</exception>
whereT:class// ensures value-types aren't passed to a null checking method
278
279
{
279
280
// To whoever is doing random code cleaning:
@@ -307,10 +308,10 @@ public static void NotNullEmptyOrNullElements<T>([ValidatedNotNull, NotNull] IEn
307
308
/// </summary>
308
309
/// <typeparam name="T">The type of the elements in the sequence.</typeparam>
309
310
/// <param name="values">The value of the argument.</param>
310
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
311
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
311
312
/// <exception cref="ArgumentException">Thrown if the tested condition is false.</exception>
/// Throws an exception if the specified parameter's value is <see cref="Guid.Empty"/>.
329
330
/// </summary>
330
331
/// <param name="value">The value of the argument.</param>
331
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
332
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
332
333
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is an empty guid (<see cref="Guid.Empty"/>.)</exception>
/// <typeparam name="TEnum">The type of enum that may define the <paramref name="value"/>.</typeparam>
523
524
/// <param name="value">The value that may be named by <typeparamref name="TEnum"/>.</param>
524
-
/// <param name="parameterName">The name of the parameter to include in the exception, if thrown.</param>
525
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
/// <typeparam name="T">The type of the parameter.</typeparam>
547
548
/// <param name="value">The value of the argument.</param>
548
-
/// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
549
+
/// <param name="parameterName">The name of the parameter to include in any thrown exception. If this argument is omitted (explicitly writing <see langword="null" /> does not qualify), the expression used in the first argument will be used as the parameter name.</param>
549
550
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="null"/> or empty.</exception>
0 commit comments