Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast follow to #44513 #44565

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/csharp/language-reference/attributes/pseudo-attributes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Attributes interpreted by the compiler: Pseudo-attributes"
ms.date: 01/2/2025
ms.date: 01/28/2025
description: "Learn about attributes you can add to code that are written to IL as modifiers. These custom attributes aren't emitted as attributes in the compiled output."
---
# Custom attributes that generate flags or options in the Intermediate Language (IL) output
Expand All @@ -16,7 +16,6 @@ You add these attributes to your code for the compiler to emit a specified Inter
| <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. |
| <xref:System.NonSerializedAttribute?displayProperty=fullName> | `notserialized` | |
| <xref:System.Runtime.InteropServices.OptionalAttribute?displayProperty=fullName> | `[opt]` | |
| <xref:System.Runtime.InteropServices.OutAttribute?displayProperty=fullName> | `[out]` | |
| <xref:System.Runtime.InteropServices.PreserveSigAttribute?displayProperty=fullName> | `preservesig` | |
| <xref:System.SerializableAttribute?displayProperty=fullName> | `serializable` | |
| <xref:System.Runtime.InteropServices.StructLayoutAttribute?displayProperty=fullName> | `auto`, `sequential`, or `explicit` | Layout options can be set using the parameters. |
Expand All @@ -28,10 +27,11 @@ Some of these custom attributes are applied using other C# syntax rather than ad
|--------------------------------------------------------------------------------------------------|----------|
| <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). |
| <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). |
| <xref:System.Runtime.InteropServices.OutAttribute?displayProperty=fullName> | Specifies the IL`[out] modifier. Use the [`out`](../keywords/method-parameters.md#out-parameter-modifier). |
| <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName> | Specifies the IL `specialname` modifier. The compiler automatically adds this modifier for methods that require it. |
| <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. |
| <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. However, you must add this attribute to any method declaration when that method is assigned to a function pointer. |

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.
The following 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 fully qualified name.

| Attribute | Comments |
|--------------------------------------------------------------------------------------------------|---------|
Expand All @@ -52,4 +52,4 @@ The following custom attributes are generally disallowed in C# source. They're l
| <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. |
| <xref:System.Runtime.CompilerServices.TupleElementNamesAttribute?displayProperty=fullName> | This attribute encodes tuple element names used in signatures. |

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.
In addition, the compiler can generate a declaration for other attributes used internally. The compiler generates these attributes 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.
Loading