-
Notifications
You must be signed in to change notification settings - Fork 28
/
global-doc-comments.xml
456 lines (439 loc) · 15.5 KB
/
global-doc-comments.xml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<?xml version="1.0" encoding="utf-8"?>
<!--
This file stores the global-used doc comments. You can use the XPath syntax to get them.
For example, you should use <include> tag to import the global doc comments:
/// <summary>
/// The test method.
/// </summary>
/// <param name="arg">
/// <include
/// file='../../global-doc-comments.xml'
/// path='g/csharp7/feature[@name="ref-returns"]/target[@name="in-parameter"]' />
/// </param>
static void F(in int arg)
{
}
Then you can reference the doc here.
-->
<g>
<!-- Elementary docs -->
<static-constructor>
<summary>
<para>
Indicates the <see langword="static"/> constructor of the current type.
</para>
<para>
This constructor will initialize some <see langword="static readonly"/> data members
of this type that can't use a simple expression to describe the initial value.
</para>
</summary>
</static-constructor>
<!-- Flags attribute usage -->
<flags-attribute>
<para>
<i>
This type is marked <see cref="global::System.FlagsAttribute"/>, which means you can use
<see langword="operator"/> | to combine multiple fields.
</i>
</para>
</flags-attribute>
<!-- Developer notes -->
<developer-notes>
<para>
<b>Developer Notes</b>
</para>
</developer-notes>
<!-- Requires static constructor invocation -->
<requires-static-constructor-invocation>
<i>
This field will only be used in the static constructor of this type. Please don't use this field in the user code.
</i>
</requires-static-constructor-invocation>
<!-- Requires compound invocation -->
<requires-compound-invocation>
<para>
<b>
<i>
This operator can only be used as compound one. For example:
</i>
</b>
<code><![CDATA[result &= expression;
result |= expression;
result ^= expression;
]]>
</code>
</para>
</requires-compound-invocation>
<!-- Large structures -->
<large-structure>
<b>
<i>
This is a large structure, which means it may cost more time to copy instance than normal structures.
I strongly recommend you append <see langword="ref readonly"/> to modify the type, as parameter or local variable modifiers,
to tell runtime that it should be copied by its reference instead of internal value.
</i>
</b>
</large-structure>
<self-type-constraint>
<para>Indicates the type implementing this interface.</para>
<para>
This type doesn't use any extra syntax to constraint such usage, but C# will check for it.
The type will include a <see langword="where"/> constraint that implements the interface itself
to declare such "self constraint" usage:
<code><![CDATA[interface ISelfType<TSelf> where TSelf : ISelfType<TSelf>]]></code>
In addition, the type should be named <c>TSelf</c> in order to tell type parameters with the others.
</para>
</self-type-constraint>
<!-- C# features -->
<!-- C# 5 -->
<csharp5>
<feature name="caller-member-name">
<target name="argument">
<para>
Indicates the name of the caller member to invoke this method.
</para>
<para>
<i>
The attribute <see cref="CallerMemberNameAttribute"/> allows the argument automatically
getting the name of the caller. For example, if the property raises the event, the argument
will pass the name of the property automatically if the argument is marked the attribute.
</i>
</para>
<para>
<i>
For the above reason, the argument will use <see langword="null"/> as the initial value
as the placeholder to allow the syntax valid during the compile time on one hand.
On the other hand, you shouldn't pass any values to this argument.
</i>
</para>
<para>
<i>
For more information, please visit
<see href="https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callermembernameattribute">
The Microsoft Docs
</see>
for more info.
</i>
</para>
</target>
</feature>
</csharp5>
<!-- C# 7 -->
<csharp7>
<feature name="deconstruction-method">
<target name="method">
<summary>
Deconstruct the current instance into multiple values, which means you can use
the value-tuple syntax like <c>(a, b, c)</c> to define your own deconstruction logic.
</summary>
</target>
</feature>
<feature name="custom-fixed">
<target name="method">
<summary>
Returns a reference as the fixed position of the current instance.
For example, the return value will be the pointer value that points to the zero-indexed
place in an array.
</summary>
<returns>A reference as the fixed position of the current instance.</returns>
<remarks>
Beginning with C# 7, we can customize the return value type of a <see langword="fixed"/> variable
if we implement a parameterless method called <c>GetPinnableReference</c>, returning by
<see langword="ref"/> or <see langword="ref readonly"/>. For example, if we hold a fixed buffer
of element type:
<code><![CDATA[class ExampleType
{
private fixed short _maskList[100];
public ref readonly short GetPinnableReference() => ref _maskList[0];
}
]]>
</code>
We can use <see langword="fixed"/> statement to define a variable of type <see langword="short"/>*
as the left-value.
<code><![CDATA[var instance = new ExampleType();
fixed (short* ptr = instance)
{
// Operation here.
}
]]>
</code>
</remarks>
</target>
</feature>
<feature name="ref-returns">
<target name="indexer-return">
<i>
This indexer returns a value by <see langword="ref"/>,
which means you can use the return value to re-assign a new value, as the same behavior
as the <see langword="set"/> accessor, therefore the indexer does not contain the setter.
</i>
</target>
<target name="method">
<i>
C# 7.3 introduces a new keyword <see langword="in"/> as the parameter modifier to make the parameter
pass by reference and be read-only. Therefore, this keyword contains 2 usages:
<list type="number">
<item>
Ensure the argument to <b>be read-only</b> and cannot be modified. Otherwise,
a new copied instance will be created to prevent any modifications on the original variable.
</item>
<item>
Ensure the argument to <b>pass by reference</b> in order to treat it as the pointer or array of elements
of this type, and treat the argument as the first element of the whole element series.
</item>
</list>
From the above meaning on this keyword, we can conclude that
we should regard it as <see langword="ref readonly"/> parameters,
but C# requires us using the keyword <see langword="in"/> as the modifier
on a parameter rather than <see langword="ref readonly"/>.
</i>
</target>
<target name="in-parameter">
<i>
Please note that the parameter is an <see langword="in"/> parameter, which has the same meaning
for <see langword="ref readonly"/> returns or locals. You can treat it as the first element
in an array of elements. Different with <see langword="ref"/> parameter, <see langword="in"/>
modifier has the same semantic as <see langword="ref readonly var"/>
instead of <see langword="ref var"/>.
</i>
</target>
</feature>
</csharp7>
<!-- C# 9 -->
<csharp9>
<feature name="records">
<target name="method" cref="PrintMembers">
<summary>
Provides an easy way to concatenate output members inside a <see langword="record"/>
or a <see langword="record struct"/> type.
</summary>
<param name="builder">
A <see cref="global::System.Text.StringBuilder"/> instance to concatenate values.
</param>
<returns>
A <see cref="bool"/> value indicating whether the method should be consumed by compiler,
by implementing to-string method <see cref="ToString"/>.
</returns>
<remarks>
<para>
By design of <see langword="record"/> and <see langword="record struct"/> types,
emit text should be formatted as follows:
<code><![CDATA[RecordType { Property1 = Value1, Property2 = Value2, Property3 = { NestedProperty = Value3 } }]]></code>
</para>
<para>
This method won't emit type name and curly brackets. If you want to customize emit text,
you can only change values inside a pair of brackets.
</para>
<para>
The suggested implementation is like this:
<code><![CDATA[private bool PrintMembers(StringBuilder builder)
{
builder.Append($"{nameof(Property1)} = {Property1}");
builder.Append(", ");
builder.Append($"{nameof(Property2)} = {Property2}");
builder.Append(", ");
builder.Append($"{nameof(Property3)} = {{ {Property3} }}");
return true;
}]]>
</code>
</para>
</remarks>
</target>
</feature>
<feature name="parameterless-struct-constructor">
<target name="constructor">
<i>
The feature "Custom parameterless struct constructor" makes the parameterless struct constructor
different with <c>default(T)</c>. If you has defined a parameterless struct constructor,
<c>new T()</c> is no longer with the same meaning as <c>default(T)</c>.
</i>
</target>
</feature>
<feature name="module-initializer">
<target name="type">
<summary>
<para>
Provides with the type that contains a module initializer method, called automatically by the CLR
(Common Language Runtime) to initialize some values.
</para>
<para>
<i>
The type is called by the compiler and the CLR (Common Language Runtime),
which means you cannot use any members in this type manually.
</i>
</para>
</summary>
</target>
<target name="method">
<summary>
Called by the runtime automatically while booting on this solution to initialize the values,
data members or any other things that can or should be initialized here.
</summary>
<remarks>
The concept <b>module</b> is different with <b>assembly</b>.
The solution can contain multiple assemblies, while each assembly can contain multiple modules.
However, due to the design of Visual Studio project file system, each assembly will only contain
one module by default.
</remarks>
</target>
</feature>
<feature name="function-pointer">
<b>
<i>
This member is only exposed for user for knowing the data structure backing implementation,
so it is disallowed to invoke it.
</i>
</b>
</feature>
</csharp9>
<!-- C# 10 -->
<csharp10>
<feature name="caller-argument-expression">
<para>
<b>The value of the argument will be automatically produced by the compiler and passed into here. You may not assign this argument.</b>
</para>
</feature>
</csharp10>
<!-- C# 11 -->
<csharp11>
<feature name="file-local">
<target name="class" when="constant">
<summary>
Provides with constants and read-only values used by code in the current file.
</summary>
</target>
<target name="class" when="extension">
<summary>
Provides with file-local extension methods.
</summary>
</target>
</feature>
<feature name="scoped-ref">
<target name="foreach-variables">
<para>
<i>
Iteration variable are implicitly <see langword="scoped"/>, which means you cannot return it outside the method
or other members that can return.
</i>
</para>
</target>
</feature>
<feature name="ref-fields">
<target name="field">
<b>
<i>
This field is not encapsulated into a property because C# doesn't support auto read-only properties
returning <see langword="ref"/> or <see langword="ref readonly"/>.
</i>
</b>
</target>
</feature>
<feature name="scoped-keyword">
<para>
The keyword <see langword="scoped"/> means the argument and local variable can only be used inside the method.
This means you cannot use this variable and argument outside the scope,
such as <c>new RefStructType(scoped_variable)</c>, <c>return scoped_variable</c> and <c>field = scoped_variable</c>.
Such expressions may store the <see langword="scoped"/> variables, unsafely expanding the variable's lifecycle.
</para>
</feature>
<feature name="static-dim">
<para>
The keyword combinations <see langword="static abstract"/>, <see langword="static virtual"/>
and <see langword="static sealed"/> are basic of DIM (default interface implementation)
for <see langword="static"/> members, introduced from C# 11.
<list type="table">
<listheader>
<term>Keyword combination</term>
<description>Meaning</description>
</listheader>
<item>
<term>
<see langword="static abstract"/>
</term>
<description>
Such members must be implemented by concrete types
(<see langword="class"/>, <see langword="struct"/>, etc.).
</description>
</item>
<item>
<term>
<see langword="static virtual"/>
</term>
<description>
Such members has a default implementation, no matter whether the member is re-implemented
(same meaning with "overridding" for instance members in <see langword="class"/> types,
but is <see langword="static"/> version) in concrete types, no compiler errors will be produced.
If such members don't have an overridden one, default implementation will be invoked;
otherwise, overridden one will be invoked.
</description>
</item>
<item>
<term>
<see langword="static sealed"/>
</term>
<description>
Such members cannot be re-implemented. Default implmentation will be frozen and no way to override it.
</description>
</item>
</list>
</para>
<para>
Please note that the rule can only be used inside a <see langword="interface"/>.
</para>
</feature>
</csharp11>
<!-- C# 12 -->
<csharp12>
<feature name="params-collections">
<target name="parameter">
<para>
If a <see langword="ref struct"/>-typed parameter is marked as <see langword="params"/>,
it will be implicit-<see langword="scoped"/>, which means you must use this variables inside the method.
Value-storages are not permitted.
</para>
<para>
Use <see cref="T:System.Diagnostics.CodeAnalysis.UnscopedRefAttribute"/> if you want to store variable values.
</para>
</target>
</feature>
</csharp12>
<!-- .NET 9 -->
<dotnet>
<version value="8">
<feature name="unsafe-accessor">
<target name="others">
<para>
This method is implemented via <see cref="T:System.Runtime.CompilerServices.UnsafeAccessorAttribute"/>,
which is just like inserting .NET implementation into the current project directly.
</para>
</target>
<target name="field-related-method">
<para>
<b>
Please note that this method will return the reference to the internal field,
but this doesn't mean you can use its reference and re-assign it.
You cannot assign a value to the field if the ref kind of a field in fact is <see langword="ref readonly"/>;
it will raise an exception to report this wrong usage.
</b>
</para>
</target>
<target type="struct">
<para>
<b>
In addition, if the target type is a <see langword="struct"/>, it requires a <see langword="ref"/> keyword;
otherwise, <see cref="System.BadImageFormatException"/> will be thrown.
</b>
</para>
</target>
</feature>
</version>
<version value="9" preview-value="4">
<feature name="unsafe-accessor">
<para>
Begin with .NET 9 preview 4, <see cref="T:System.Runtime.CompilerServices.UnsafeAccessorAttribute"/>
supports with generic-typed references.
</para>
</feature>
</version>
</dotnet>
</g>