Skip to content

Commit 7bd3e93

Browse files
committed
Fixes #43110
Add a list of attributes that are written by the compiler that shouldn't be added in users' source code.
1 parent a4cbd47 commit 7bd3e93

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,30 @@ You add these attributes to your code for the compiler to emit specified Interme
2020
- <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName>: Specifies the IL `auto`, `sequential`, or `explicit` modifiers. Layout options can be set using the parameters.
2121
- <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.
2222

23-
Other custom attributes are generally applied using other C# syntax rather than adding the attribute to your source code.
23+
Some of these custom attributes are generally applied using other C# syntax rather than adding the attribute to your source code.
2424

2525
- <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)
2626
- <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).
2727
- <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName>: Specifies the IL `specialname` modifier. The compiler automatically uses the for methods that require the `specialname` modifier.
2828
- <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) requires its use.
29+
30+
The following custom attributes are generally disallowed in C# source. They are listed here to aid library authors who use reflection, and to ensure you don't create custom attributes with the same name.
31+
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 [IndexerNameAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.indexernameattribute). This attributes notes the default indexer when its name has been customized. 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 attributes 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 attributes indicates that a parameter has the `readonly ref` modifier. Ut 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` on non-array parameters.
45+
- <xref:System.Runtime.CompilerServices.RefSafetyRulesAttribute?displayProperty=fullName>: This attributes specifies the C# version that is required in order to understand ref safety annotations in the assembly. Ref safety rules have evolved as new features have been added to the language.
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.
48+
49+
In addition, the compiler may 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, but are generated by the compiler as an `internal` type declaration in any assembly where the attribute is needed.

0 commit comments

Comments
 (0)