Skip to content

Commit 6019904

Browse files
committed
Use .NET original xml document of nullable
1 parent a1e6632 commit 6019904

1 file changed

Lines changed: 55 additions & 101 deletions

File tree

  • src/dotnetCampus.LatestCSharpFeatures/Nullable

src/dotnetCampus.LatestCSharpFeatures/Nullable/Nullable.cs

Lines changed: 55 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,245 +1,199 @@
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
25
{
3-
#if NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0_OR_GREATER
6+
#if NETSTANDARD2_1 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0_OR_GREATER
47
#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>
89
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
910
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
1011
public
1112
#else
1213
internal
1314
#endif
14-
sealed class AllowNullAttribute : Attribute { }
15+
sealed class AllowNullAttribute : Attribute { }
1516

16-
/// <summary>
17-
/// 标记一个可空的输入实际上不应该传入 null。
18-
/// </summary>
17+
/// <summary>Specifies that null is disallowed as an input even if the corresponding type allows it.</summary>
1918
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
2019
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
2120
public
2221
#else
2322
internal
2423
#endif
25-
sealed class DisallowNullAttribute : Attribute { }
24+
sealed class DisallowNullAttribute : Attribute { }
2625

27-
/// <summary>
28-
/// 标记一个非空的返回值实际上可能会返回 null,返回值包括输出参数。
29-
/// </summary>
26+
/// <summary>Specifies that an output may be null even if the corresponding type disallows it.</summary>
3027
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
3128
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
3229
public
3330
#else
3431
internal
3532
#endif
36-
sealed class MaybeNullAttribute : Attribute { }
33+
sealed class MaybeNullAttribute : Attribute { }
3734

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>
4136
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
4237
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
4338
public
4439
#else
4540
internal
4641
#endif
47-
sealed class NotNullAttribute : Attribute { }
42+
sealed class NotNullAttribute : Attribute { }
4843

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>
5245
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
5346
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
5447
public
5548
#else
5649
internal
5750
#endif
58-
sealed class MaybeNullWhenAttribute : Attribute
51+
sealed class MaybeNullWhenAttribute : Attribute
5952
{
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>
6457
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
6558

66-
/// <summary>
67-
/// 获取返回值决定是否可为空的那个判断值。
68-
/// </summary>
59+
/// <summary>Gets the return value condition.</summary>
6960
public bool ReturnValue { get; }
7061
}
7162

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>
7564
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
7665
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
7766
public
7867
#else
7968
internal
8069
#endif
81-
sealed class NotNullWhenAttribute : Attribute
70+
sealed class NotNullWhenAttribute : Attribute
8271
{
83-
/// <summary>
84-
/// 使用 true 或者 false 决定输出参数是否不可为 null。
85-
/// </summary>
72+
/// <summary>Initializes the attribute with the specified return value condition.</summary>
8673
/// <param name="returnValue">
87-
/// 如果方法或属性的返回值等于这个值,那么输出参数则不可为 null,否则输出参数是可能为 null 的。
74+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
8875
/// </param>
8976
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
9077

91-
/// <summary>
92-
/// 获取返回值决定是否不可为空的那个判断值。
93-
/// </summary>
78+
/// <summary>Gets the return value condition.</summary>
9479
public bool ReturnValue { get; }
9580
}
9681

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>
10083
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
10184
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
10285
public
10386
#else
10487
internal
10588
#endif
106-
sealed class NotNullIfNotNullAttribute : Attribute
89+
sealed class NotNullIfNotNullAttribute : Attribute
10790
{
108-
/// <summary>
109-
/// 使用一个参数名称决定返回值是否可能为 null。
110-
/// </summary>
91+
/// <summary>Initializes the attribute with the associated parameter name.</summary>
11192
/// <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.
11394
/// </param>
11495
public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;
11596

116-
/// <summary>
117-
/// 获取决定输出参数或者返回值是否可能为空的那个参数名称。
118-
/// </summary>
97+
/// <summary>Gets the associated parameter name.</summary>
11998
public string ParameterName { get; }
12099
}
121100

122-
/// <summary>
123-
/// 指定一个方法是不可能返回的。
124-
/// </summary>
101+
/// <summary>Applied to a method that will never return under any circumstance.</summary>
125102
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
126103
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
127104
public
128105
#else
129106
internal
130107
#endif
131-
sealed class DoesNotReturnAttribute : Attribute { }
108+
sealed class DoesNotReturnAttribute : Attribute { }
132109

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>
136111
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
137112
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
138113
public
139114
#else
140115
internal
141116
#endif
142-
sealed class DoesNotReturnIfAttribute : Attribute
117+
sealed class DoesNotReturnIfAttribute : Attribute
143118
{
144-
/// <summary>
145-
/// 使用 true/false 决定方法是否可能返回。
146-
/// </summary>
119+
/// <summary>Initializes the attribute with the specified parameter value.</summary>
147120
/// <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.
149123
/// </param>
150124
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
151125

152-
/// <summary>
153-
/// 获取决定方法是否可返回的那个参数的值。
154-
/// </summary>
126+
/// <summary>Gets the condition parameter value.</summary>
155127
public bool ParameterValue { get; }
156128
}
157129
#endif
158130

159131
#if NET5_0_OR_GREATER
160132
#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>
164134
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
165135
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
166136
public
167137
#else
168138
internal
169139
#endif
170-
sealed class MemberNotNullAttribute : Attribute
140+
sealed class MemberNotNullAttribute : Attribute
171141
{
172-
/// <summary>
173-
/// 指定调用了此方法后,所列出的字段和属性成员将不会为 null。
174-
/// </summary>
142+
/// <summary>Initializes the attribute with a field or property member.</summary>
175143
/// <param name="member">
176-
/// 将保证不会为 null 的字段或属性名称。
144+
/// The field or property member that is promised to be not-null.
177145
/// </param>
178146
public MemberNotNullAttribute(string member) => Members = new[] { member };
179147

180-
/// <summary>
181-
/// 指定调用了此方法后,所列出的字段和属性成员将不会为 null。
182-
/// </summary>
148+
/// <summary>Initializes the attribute with the list of field and property members.</summary>
183149
/// <param name="members">
184-
/// 将保证不会为 null 的字段或属性名称列表。
150+
/// The list of field and property members that are promised to be not-null.
185151
/// </param>
186152
public MemberNotNullAttribute(params string[] members) => Members = members;
187153

188-
/// <summary>
189-
/// 调用了此方法后保证不会为 null 的字段或属性名称列表。
190-
/// </summary>
154+
/// <summary>Gets field or property member names.</summary>
191155
public string[] Members { get; }
192156
}
193157

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>
197159
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
198160
#if USE_PUBLIC_LATEST_CSHARP_FEATURES
199161
public
200162
#else
201163
internal
202164
#endif
203-
sealed class MemberNotNullWhenAttribute : Attribute
165+
sealed class MemberNotNullWhenAttribute : Attribute
204166
{
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>
208168
/// <param name="returnValue">
209-
/// 如果方法或属性的返回值等于这个值,那么所列出的字段和属性成员将不会为 null
169+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
210170
/// </param>
211171
/// <param name="member">
212-
/// 将保证不会为 null 的字段或属性名称列表。
172+
/// The field or property member that is promised to be not-null.
213173
/// </param>
214174
public MemberNotNullWhenAttribute(bool returnValue, string member)
215175
{
216176
ReturnValue = returnValue;
217177
Members = new[] { member };
218178
}
219179

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>
223181
/// <param name="returnValue">
224-
/// 如果方法或属性的返回值等于这个值,那么所列出的字段和属性成员将不会为 null
182+
/// The return value condition. If the method returns this value, the associated parameter will not be null.
225183
/// </param>
226184
/// <param name="members">
227-
/// 将保证不会为 null 的字段或属性名称列表。
185+
/// The list of field and property members that are promised to be not-null.
228186
/// </param>
229187
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
230188
{
231189
ReturnValue = returnValue;
232190
Members = members;
233191
}
234192

235-
/// <summary>
236-
/// 获取返回值决定是否不可为空的那个判断值。
237-
/// </summary>
193+
/// <summary>Gets the return value condition.</summary>
238194
public bool ReturnValue { get; }
239195

240-
/// <summary>
241-
/// 调用了此方法后保证不会为 null 的字段或属性名称列表。
242-
/// </summary>
196+
/// <summary>Gets field or property member names.</summary>
243197
public string[] Members { get; }
244198
}
245199
#endif

0 commit comments

Comments
 (0)