Skip to content

Commit 2ceced9

Browse files
committed
Respond to feedback.
1 parent a92a30a commit 2ceced9

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

docs/csharp/language-reference/attributes/pseudo-attributes.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,49 @@ description: "Learn about attributes you can add to code that are written to IL
77

88
You add these attributes to your code for the compiler to emit a specified Intermediate Language (IL) modifier. These attributes instruct the compiler to include the corresponding IL modifier in the output.
99

10-
- <xref:System.Runtime.InteropServices.ComImportAttribute?displayProperty=fullName>: Specifies the `import` modifier.
11-
- <xref:System.Runtime.InteropServices.DllImportAttribute?displayProperty=fullName>: Specifies the `pinvokeimpl` modifier. You can add options listed in the constructor.
12-
- <xref:System.Runtime.InteropServices.FieldOffsetAttribute?displayProperty=fullName>: Specifies the `.field` offset modifier.
13-
- <xref:System.Runtime.InteropServices.MarshalAsAttribute>: Specifies the IL `marshal` modifier. You can set options listed in the constructor.
14-
4- <xref:System.Runtime.CompilerServices.MethodImplAttribute?displayProperty=fullName>: Maps to the IL `flag` modifier. Constructor arguments specify specific named flags such as `aggressiveinlining` or `forwardref`. These flags also specify the `native`, `managed`, or `optil` modifiers for the <xref:System.Runtime.CompilerServices.MethodCodeType?displayProperty=fullName> field.
15-
- <xref:System.NonSerializedAttribute?displayProperty=fullName>: Specifies the IL `notserialized` modifier.
16-
- <xref:System.Runtime.InteropServices.OptionalAttribute?displayProperty=fullName>: Specifies the IL `[opt]` modifier.
17-
- <xref:System.Runtime.InteropServices.OutAttribute?displayProperty=fullName>: Specifies the IL `[out]` modifier.
18-
- <xref:System.Runtime.InteropServices.PreserveSigAttribute?displayProperty=fullName>: Specifies the IL `preservesig` modifier.
19-
- <xref:System.SerializableAttribute?displayProperty=fullName>: Specifies the IL `serializable` modifier.
20-
- <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName>: Specifies the IL `auto`, `sequential`, or `explicit` modifiers. Layout options can be set using the parameters.
21-
- <xref:System.Runtime.CompilerServices.IndexerNameAttribute?displayProperty=fullName>: You add this attribute to an indexer to set a different method name. By default, indexers are compiled to a property named `Item`. You can specify a different name using this attribute.
10+
| Attribute | Modifier | Comments |
11+
|--------------------------------------------------------------------------------------|-----------------|-----------|
12+
| <xref:System.Runtime.InteropServices.ComImportAttribute?displayProperty=fullName> | `import` | |
13+
| <xref:System.Runtime.InteropServices.DllImportAttribute?displayProperty=fullName> | `pinvokeimpl` | You can add options listed in the constructor. |
14+
| <xref:System.Runtime.InteropServices.FieldOffsetAttribute?displayProperty=fullName> | `.field` | This sets the field offset for memory layout. |
15+
| <xref:System.Runtime.InteropServices.MarshalAsAttribute> | `marshal` | You can set options listed in the constructor. |
16+
| <xref:System.Runtime.CompilerServices.MethodImplAttribute?displayProperty=fullName> | `flag` | Constructor arguments specify specific named flags such as `aggressiveinlining` or `forwardref`. These flags also specify the `native`, `managed`, or `optil` modifiers for the <xref:System.Runtime.CompilerServices.MethodCodeType?displayProperty=fullName> field. |
17+
| <xref:System.NonSerializedAttribute?displayProperty=fullName> | `notserialized` | |
18+
| <xref:System.Runtime.InteropServices.OptionalAttribute?displayProperty=fullName> | `[opt]` | |
19+
| <xref:System.Runtime.InteropServices.OutAttribute?displayProperty=fullName> | `[out]` | |
20+
| <xref:System.Runtime.InteropServices.PreserveSigAttribute?displayProperty=fullName> | `preservesig` | |
21+
| <xref:System.SerializableAttribute?displayProperty=fullName> | `serializable` | |
22+
| <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName> | `auto`, `sequential`, or `explicit` | Layout options can be set using the parameters. |
23+
| <xref:System.Runtime.CompilerServices.IndexerNameAttribute?displayProperty=fullName> | | You add this attribute to an indexer to set a different method name. By default, indexers are compiled to a property named `Item`. You can specify a different name using this attribute. |
2224

2325
Some of these custom attributes are applied using other C# syntax rather than adding the attribute to your source code.
2426

25-
- <xref:System.Runtime.InteropServices.DefaultParameterValueAttribute?displayProperty=fullName>: Specifies the default value for the parameter. Use the [default parameter syntax](../../methods.md#optional-parameters-and-arguments).
26-
- <xref:System.Runtime.InteropServices.InAttribute?displayProperty=fullName>: Specifies the IL `[in]` modifier. Use the [`in`](../keywords/method-parameters.md#in-parameter-modifier) or [`ref readonly`](../keywords/method-parameters.md#ref-readonly-modifier).
27-
- <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName>: Specifies the IL `specialname` modifier. The compiler automatically uses the for methods that require the `specialname` modifier.
28-
- <xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute?displayProperty=nameWithType>: This attribute is required for the `delegate*` feature. The compiler adds it to any [`delegate*`](../unsafe-code.md#function-pointers) that requires its use.
27+
| Attribute | Comments |
28+
|--------------------------------------------------------------------------------------------------|----------|
29+
| <xref:System.Runtime.InteropServices.DefaultParameterValueAttribute?displayProperty=fullName> | Specifies the default value for the parameter. Use the [default parameter syntax](../../methods.md#optional-parameters-and-arguments). |
30+
| <xref:System.Runtime.InteropServices.InAttribute?displayProperty=fullName> | Specifies the IL `[in]` modifier. Use the [`in`](../keywords/method-parameters.md#in-parameter-modifier) or [`ref readonly`](../keywords/method-parameters.md#ref-readonly-modifier). |
31+
| <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName> | Specifies the IL `specialname` modifier. The compiler automatically adds this modifier for methods that require it. |
32+
| <xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute?displayProperty=nameWithType> | This attribute is required for the `delegate*` feature. The compiler adds it to any [`delegate*`](../unsafe-code.md#function-pointers) that requires its use. |
2933

3034
The following custom attributes are generally disallowed in C# source. They're listed here to aid library authors who use reflection, and to ensure you don't create custom attributes with the same name.
3135

32-
- <xref:System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute?displayProperty=fullName>: Prevents downlevel compilers from using metadata it can't safely understand.
33-
- <xref:System.Runtime.CompilerServices.DecimalConstantAttribute?displayProperty=fullName>: Encodes `const decimal` fields. The runtime doesn't support `decimal` values as constant values.
34-
- <xref:System.Reflection.DefaultMemberAttribute?displayProperty=fullName>: Encodes indexers with <xref:System.Runtime.CompilerServices.IndexerNameAttribute?displayProperty=fullName>. This attribute notes the default indexer when its name is different than `Item`. This attribute is allowed in source.
35-
- <xref:System.Runtime.CompilerServices.DynamicAttribute?displayProperty=fullName>: Encodes whether a type in a signature is `dynamic` (versus `object`).
36-
- <xref:System.Runtime.CompilerServices.ExtensionAttribute?displayProperty=fullName>: This attribute notes extension methods. The compiler also places this attribute on the containing classes.
37-
- <xref:System.Runtime.CompilerServices.FixedBufferAttribute?displayProperty=fullName>: This attribute specifies `fixed` struct fields.
38-
- <xref:System.Runtime.CompilerServices.IsByRefLikeAttribute?displayProperty=fullName>: This attribute specifies a `ref` struct.
39-
- <xref:System.Runtime.CompilerServices.IsReadOnlyAttribute?displayProperty=fullName>: This attribute indicates that a parameter has the `in` modifier. It distinguishes `in` parameters from `readonly ref` or `[In] ref`.
40-
- <xref:System.Runtime.CompilerServices.RequiresLocationAttribute?displayProperty=fullName>: This attribute indicates that a parameter has the `readonly ref` modifier. It distinguishes `readonly ref` from `in` or `[In] ref`.
41-
- <xref:System.Runtime.CompilerServices.IsUnmanagedAttribute?displayProperty=fullName> - This attribute specifies the `unmanaged` constraint on a type parameter.
42-
- <xref:System.Runtime.CompilerServices.NullableAttribute?displayProperty=fullName>, <xref:System.Runtime.CompilerServices.NullableContextAttribute?displayProperty=fullName>, <xref:System.Runtime.CompilerServices.NullablePublicOnlyAttribute?displayProperty=fullName>: These attributes encode nullable annotations in your source code.
43-
- <xref:System.ParamArrayAttribute?displayProperty=fullName>: This attribute encodes the `params` modifier on array parameters.
44-
- <xref:System.Runtime.CompilerServices.ParamCollectionAttribute?displayProperty=fullName> This attribute encodes the `params` modifier on non-array parameters.
45-
- <xref:System.Runtime.CompilerServices.RefSafetyRulesAttribute?displayProperty=fullName>: This attribute specifies the C# version that is required in order to understand ref safety annotations in the assembly. Ref safety rules evolve as C# gets new features.
46-
- <xref:System.Runtime.CompilerServices.RequiredMemberAttribute?displayProperty=fullName>: This attribute indicates that the `required` modifier was placed on a member declaration. It's the encoding of the [required members](../keywords/required.md) language feature.
47-
- <xref:System.Runtime.CompilerServices.TupleElementNamesAttribute?displayProperty=fullName>: This attribute encodes tuple element names used in signatures.
36+
| Attribute | Comments |
37+
|--------------------------------------------------------------------------------------------------|---------|
38+
| <xref:System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute?displayProperty=fullName> | Prevents downlevel compilers from using metadata it can't safely understand. |
39+
| <xref:System.Runtime.CompilerServices.DecimalConstantAttribute?displayProperty=fullName> | Encodes `const decimal` fields. The runtime doesn't support `decimal` values as constant values. |
40+
| <xref:System.Reflection.DefaultMemberAttribute?displayProperty=fullName> | Encodes indexers with <xref:System.Runtime.CompilerServices.IndexerNameAttribute?displayProperty=fullName>. This attribute notes the default indexer when its name is different than `Item`. This attribute is allowed in source. |
41+
| <xref:System.Runtime.CompilerServices.DynamicAttribute?displayProperty=fullName> | Encodes whether a type in a signature is `dynamic` (versus `object`). |
42+
| <xref:System.Runtime.CompilerServices.ExtensionAttribute?displayProperty=fullName> | This attribute notes extension methods. The compiler also places this attribute on the containing classes. |
43+
| <xref:System.Runtime.CompilerServices.FixedBufferAttribute?displayProperty=fullName> | This attribute specifies `fixed` struct fields. |
44+
| <xref:System.Runtime.CompilerServices.IsByRefLikeAttribute?displayProperty=fullName> | This attribute specifies a `ref` struct. |
45+
| <xref:System.Runtime.CompilerServices.IsReadOnlyAttribute?displayProperty=fullName> | This attribute indicates that a parameter has the `in` modifier. It distinguishes `in` parameters from `readonly ref` or `[In] ref`. |
46+
| <xref:System.Runtime.CompilerServices.RequiresLocationAttribute?displayProperty=fullName> | This attribute indicates that a parameter has the `readonly ref` modifier. It distinguishes `readonly ref` from `in` or `[In] ref`. |
47+
| <xref:System.Runtime.CompilerServices.IsUnmanagedAttribute?displayProperty=fullName> | This attribute specifies the `unmanaged` constraint on a type parameter. |
48+
| <xref:System.Runtime.CompilerServices.NullableAttribute?displayProperty=fullName>, <xref:System.Runtime.CompilerServices.NullableContextAttribute?displayProperty=fullName>, <xref:System.Runtime.CompilerServices.NullablePublicOnlyAttribute?displayProperty=fullName> | These attributes encode nullable annotations in your source code. |
49+
| <xref:System.ParamArrayAttribute?displayProperty=fullName> | This attribute encodes the `params` modifier on array parameters. |
50+
| <xref:System.Runtime.CompilerServices.ParamCollectionAttribute?displayProperty=fullName> | This attribute encodes the `params` modifier on non-array parameters. |
51+
| <xref:System.Runtime.CompilerServices.RefSafetyRulesAttribute?displayProperty=fullName> | This attribute specifies the C# version that is required in order to understand ref safety annotations in the assembly. Ref safety rules evolve as C# gets new features. |
52+
| <xref:System.Runtime.CompilerServices.RequiredMemberAttribute?displayProperty=fullName> | This attribute indicates that the `required` modifier was placed on a member declaration. It's the encoding of the [required members](../keywords/required.md) language feature. |
53+
| <xref:System.Runtime.CompilerServices.TupleElementNamesAttribute?displayProperty=fullName> | This attribute encodes tuple element names used in signatures. |
4854

49-
In addition, the compiler can generate a declaration for other attributes used internally. For this reason, you should assume other attributes in the <xref:System.Runtime.CompilerServices> namespace. Some aren't in the .NET Runtime. Instead, the compiler synthesizes a definition for an `internal` type declaration in any assembly where the attribute is needed.
55+
In addition, the compiler can generate a declaration for other attributes used internally. The compiler generates these in the <xref:System.Runtime.CompilerServices> namespace for its own use. Some aren't in the .NET Runtime libraries. Instead, the compiler synthesizes a definition for an `internal` type declaration in any assembly where the attribute is needed.

0 commit comments

Comments
 (0)