|
1 | | -namespace System.Diagnostics.CodeAnalysis |
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace System.Diagnostics.CodeAnalysis |
2 | 5 | { |
3 | | -#if NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0_OR_GREATER |
| 6 | +#if NETSTANDARD2_1 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0_OR_GREATER |
4 | 7 | #else |
5 | | - /// <summary> |
6 | | - /// 标记一个不可空的输入实际上是可以传入 null 的。 |
7 | | - /// </summary> |
| 8 | + /// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary> |
8 | 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] |
9 | 10 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
10 | 11 | public |
11 | 12 | #else |
12 | 13 | internal |
13 | 14 | #endif |
14 | | - sealed class AllowNullAttribute : Attribute { } |
| 15 | + sealed class AllowNullAttribute : Attribute { } |
15 | 16 |
|
16 | | - /// <summary> |
17 | | - /// 标记一个可空的输入实际上不应该传入 null。 |
18 | | - /// </summary> |
| 17 | + /// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary> |
19 | 18 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] |
20 | 19 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
21 | 20 | public |
22 | 21 | #else |
23 | 22 | internal |
24 | 23 | #endif |
25 | | - sealed class DisallowNullAttribute : Attribute { } |
| 24 | + sealed class DisallowNullAttribute : Attribute { } |
26 | 25 |
|
27 | | - /// <summary> |
28 | | - /// 标记一个非空的返回值实际上可能会返回 null,返回值包括输出参数。 |
29 | | - /// </summary> |
| 26 | + /// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary> |
30 | 27 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] |
31 | 28 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
32 | 29 | public |
33 | 30 | #else |
34 | 31 | internal |
35 | 32 | #endif |
36 | | - sealed class MaybeNullAttribute : Attribute { } |
| 33 | + sealed class MaybeNullAttribute : Attribute { } |
37 | 34 |
|
38 | | - /// <summary> |
39 | | - /// 标记一个可空的返回值实际上是不可能返回 null 的,返回值包括输出参数。 |
40 | | - /// </summary> |
| 35 | + /// <summary>Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.</summary> |
41 | 36 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] |
42 | 37 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
43 | 38 | public |
44 | 39 | #else |
45 | 40 | internal |
46 | 41 | #endif |
47 | | - sealed class NotNullAttribute : Attribute { } |
| 42 | + sealed class NotNullAttribute : Attribute { } |
48 | 43 |
|
49 | | - /// <summary> |
50 | | - /// 当返回指定的 true/false 时某个输出参数才可能为 null,而返回相反的值时那个输出参数则不可为 null。 |
51 | | - /// </summary> |
| 44 | + /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter may be null even if the corresponding type disallows it.</summary> |
52 | 45 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] |
53 | 46 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
54 | 47 | public |
55 | 48 | #else |
56 | 49 | internal |
57 | 50 | #endif |
58 | | - sealed class MaybeNullWhenAttribute : Attribute |
| 51 | + sealed class MaybeNullWhenAttribute : Attribute |
59 | 52 | { |
60 | | - /// <summary> |
61 | | - /// 使用 true 或者 false 决定输出参数是否可能为 null。 |
62 | | - /// </summary> |
63 | | - /// <param name="returnValue">如果方法返回值等于这个值,那么输出参数则可能为 null,否则输出参数是不可为 null 的。</param> |
| 53 | + /// <summary>Initializes the attribute with the specified return value condition.</summary> |
| 54 | + /// <param name="returnValue"> |
| 55 | + /// The return value condition. If the method returns this value, the associated parameter may be null. |
| 56 | + /// </param> |
64 | 57 | public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; |
65 | 58 |
|
66 | | - /// <summary> |
67 | | - /// 获取返回值决定是否可为空的那个判断值。 |
68 | | - /// </summary> |
| 59 | + /// <summary>Gets the return value condition.</summary> |
69 | 60 | public bool ReturnValue { get; } |
70 | 61 | } |
71 | 62 |
|
72 | | - /// <summary> |
73 | | - /// 当返回指定的 true/false 时,某个输出参数不可为 null,而返回相反的值时那个输出参数则可能为 null。 |
74 | | - /// </summary> |
| 63 | + /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary> |
75 | 64 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] |
76 | 65 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
77 | 66 | public |
78 | 67 | #else |
79 | 68 | internal |
80 | 69 | #endif |
81 | | - sealed class NotNullWhenAttribute : Attribute |
| 70 | + sealed class NotNullWhenAttribute : Attribute |
82 | 71 | { |
83 | | - /// <summary> |
84 | | - /// 使用 true 或者 false 决定输出参数是否不可为 null。 |
85 | | - /// </summary> |
| 72 | + /// <summary>Initializes the attribute with the specified return value condition.</summary> |
86 | 73 | /// <param name="returnValue"> |
87 | | - /// 如果方法或属性的返回值等于这个值,那么输出参数则不可为 null,否则输出参数是可能为 null 的。 |
| 74 | + /// The return value condition. If the method returns this value, the associated parameter will not be null. |
88 | 75 | /// </param> |
89 | 76 | public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; |
90 | 77 |
|
91 | | - /// <summary> |
92 | | - /// 获取返回值决定是否不可为空的那个判断值。 |
93 | | - /// </summary> |
| 78 | + /// <summary>Gets the return value condition.</summary> |
94 | 79 | public bool ReturnValue { get; } |
95 | 80 | } |
96 | 81 |
|
97 | | - /// <summary> |
98 | | - /// 指定的参数传入 null 时才可能返回 null,指定的参数传入非 null 时就不可能返回 null。 |
99 | | - /// </summary> |
| 82 | + /// <summary>Specifies that the output will be non-null if the named parameter is non-null.</summary> |
100 | 83 | [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] |
101 | 84 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
102 | 85 | public |
103 | 86 | #else |
104 | 87 | internal |
105 | 88 | #endif |
106 | | - sealed class NotNullIfNotNullAttribute : Attribute |
| 89 | + sealed class NotNullIfNotNullAttribute : Attribute |
107 | 90 | { |
108 | | - /// <summary> |
109 | | - /// 使用一个参数名称决定返回值是否可能为 null。 |
110 | | - /// </summary> |
| 91 | + /// <summary>Initializes the attribute with the associated parameter name.</summary> |
111 | 92 | /// <param name="parameterName"> |
112 | | - /// 指定一个方法传入参数的名称,当这个参数传入非 null 时,输出参数或者返回值就是非 null;而这个参数传入可为 null 时,输出参数或者返回值就可为 null。 |
| 93 | + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. |
113 | 94 | /// </param> |
114 | 95 | public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; |
115 | 96 |
|
116 | | - /// <summary> |
117 | | - /// 获取决定输出参数或者返回值是否可能为空的那个参数名称。 |
118 | | - /// </summary> |
| 97 | + /// <summary>Gets the associated parameter name.</summary> |
119 | 98 | public string ParameterName { get; } |
120 | 99 | } |
121 | 100 |
|
122 | | - /// <summary> |
123 | | - /// 指定一个方法是不可能返回的。 |
124 | | - /// </summary> |
| 101 | + /// <summary>Applied to a method that will never return under any circumstance.</summary> |
125 | 102 | [AttributeUsage(AttributeTargets.Method, Inherited = false)] |
126 | 103 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
127 | 104 | public |
128 | 105 | #else |
129 | 106 | internal |
130 | 107 | #endif |
131 | | - sealed class DoesNotReturnAttribute : Attribute { } |
| 108 | + sealed class DoesNotReturnAttribute : Attribute { } |
132 | 109 |
|
133 | | - /// <summary> |
134 | | - /// 在方法的输入参数上指定一个条件,当这个参数传入了指定的 true/false 时方法不可能返回。 |
135 | | - /// </summary> |
| 110 | + /// <summary>Specifies that the method will not return if the associated Boolean parameter is passed the specified value.</summary> |
136 | 111 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] |
137 | 112 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
138 | 113 | public |
139 | 114 | #else |
140 | 115 | internal |
141 | 116 | #endif |
142 | | - sealed class DoesNotReturnIfAttribute : Attribute |
| 117 | + sealed class DoesNotReturnIfAttribute : Attribute |
143 | 118 | { |
144 | | - /// <summary> |
145 | | - /// 使用 true/false 决定方法是否可能返回。 |
146 | | - /// </summary> |
| 119 | + /// <summary>Initializes the attribute with the specified parameter value.</summary> |
147 | 120 | /// <param name="parameterValue"> |
148 | | - /// 在方法的输入参数上指定一个条件,当这个参数传入的值等于这里设定的值时,方法不可能返回。 |
| 121 | + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to |
| 122 | + /// the associated parameter matches this value. |
149 | 123 | /// </param> |
150 | 124 | public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; |
151 | 125 |
|
152 | | - /// <summary> |
153 | | - /// 获取决定方法是否可返回的那个参数的值。 |
154 | | - /// </summary> |
| 126 | + /// <summary>Gets the condition parameter value.</summary> |
155 | 127 | public bool ParameterValue { get; } |
156 | 128 | } |
157 | 129 | #endif |
158 | 130 |
|
159 | 131 | #if NET5_0_OR_GREATER |
160 | 132 | #else |
161 | | - /// <summary> |
162 | | - /// 调用了此方法后,即可保证列表中所列出的字段和属性成员将不会为 null。 |
163 | | - /// </summary> |
| 133 | + /// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary> |
164 | 134 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] |
165 | 135 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
166 | 136 | public |
167 | 137 | #else |
168 | 138 | internal |
169 | 139 | #endif |
170 | | - sealed class MemberNotNullAttribute : Attribute |
| 140 | + sealed class MemberNotNullAttribute : Attribute |
171 | 141 | { |
172 | | - /// <summary> |
173 | | - /// 指定调用了此方法后,所列出的字段和属性成员将不会为 null。 |
174 | | - /// </summary> |
| 142 | + /// <summary>Initializes the attribute with a field or property member.</summary> |
175 | 143 | /// <param name="member"> |
176 | | - /// 将保证不会为 null 的字段或属性名称。 |
| 144 | + /// The field or property member that is promised to be not-null. |
177 | 145 | /// </param> |
178 | 146 | public MemberNotNullAttribute(string member) => Members = new[] { member }; |
179 | 147 |
|
180 | | - /// <summary> |
181 | | - /// 指定调用了此方法后,所列出的字段和属性成员将不会为 null。 |
182 | | - /// </summary> |
| 148 | + /// <summary>Initializes the attribute with the list of field and property members.</summary> |
183 | 149 | /// <param name="members"> |
184 | | - /// 将保证不会为 null 的字段或属性名称列表。 |
| 150 | + /// The list of field and property members that are promised to be not-null. |
185 | 151 | /// </param> |
186 | 152 | public MemberNotNullAttribute(params string[] members) => Members = members; |
187 | 153 |
|
188 | | - /// <summary> |
189 | | - /// 调用了此方法后保证不会为 null 的字段或属性名称列表。 |
190 | | - /// </summary> |
| 154 | + /// <summary>Gets field or property member names.</summary> |
191 | 155 | public string[] Members { get; } |
192 | 156 | } |
193 | 157 |
|
194 | | - /// <summary> |
195 | | - /// 当返回指定的 true/false 时,即可保证列表中所列出的字段和属性成员将不会为 null。 |
196 | | - /// </summary> |
| 158 | + /// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition.</summary> |
197 | 159 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] |
198 | 160 | #if USE_PUBLIC_LATEST_CSHARP_FEATURES |
199 | 161 | public |
200 | 162 | #else |
201 | 163 | internal |
202 | 164 | #endif |
203 | | - sealed class MemberNotNullWhenAttribute : Attribute |
| 165 | + sealed class MemberNotNullWhenAttribute : Attribute |
204 | 166 | { |
205 | | - /// <summary> |
206 | | - /// 使用 true 或者 false 决定是否所列出的字段和属性成员将不会为 null。 |
207 | | - /// </summary> |
| 167 | + /// <summary>Initializes the attribute with the specified return value condition and a field or property member.</summary> |
208 | 168 | /// <param name="returnValue"> |
209 | | - /// 如果方法或属性的返回值等于这个值,那么所列出的字段和属性成员将不会为 null。 |
| 169 | + /// The return value condition. If the method returns this value, the associated parameter will not be null. |
210 | 170 | /// </param> |
211 | 171 | /// <param name="member"> |
212 | | - /// 将保证不会为 null 的字段或属性名称列表。 |
| 172 | + /// The field or property member that is promised to be not-null. |
213 | 173 | /// </param> |
214 | 174 | public MemberNotNullWhenAttribute(bool returnValue, string member) |
215 | 175 | { |
216 | 176 | ReturnValue = returnValue; |
217 | 177 | Members = new[] { member }; |
218 | 178 | } |
219 | 179 |
|
220 | | - /// <summary> |
221 | | - /// 使用 true 或者 false 决定是否所列出的字段和属性成员将不会为 null。 |
222 | | - /// </summary> |
| 180 | + /// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary> |
223 | 181 | /// <param name="returnValue"> |
224 | | - /// 如果方法或属性的返回值等于这个值,那么所列出的字段和属性成员将不会为 null。 |
| 182 | + /// The return value condition. If the method returns this value, the associated parameter will not be null. |
225 | 183 | /// </param> |
226 | 184 | /// <param name="members"> |
227 | | - /// 将保证不会为 null 的字段或属性名称列表。 |
| 185 | + /// The list of field and property members that are promised to be not-null. |
228 | 186 | /// </param> |
229 | 187 | public MemberNotNullWhenAttribute(bool returnValue, params string[] members) |
230 | 188 | { |
231 | 189 | ReturnValue = returnValue; |
232 | 190 | Members = members; |
233 | 191 | } |
234 | 192 |
|
235 | | - /// <summary> |
236 | | - /// 获取返回值决定是否不可为空的那个判断值。 |
237 | | - /// </summary> |
| 193 | + /// <summary>Gets the return value condition.</summary> |
238 | 194 | public bool ReturnValue { get; } |
239 | 195 |
|
240 | | - /// <summary> |
241 | | - /// 调用了此方法后保证不会为 null 的字段或属性名称列表。 |
242 | | - /// </summary> |
| 196 | + /// <summary>Gets field or property member names.</summary> |
243 | 197 | public string[] Members { get; } |
244 | 198 | } |
245 | 199 | #endif |
|
0 commit comments