Introduce pseudo-attributes page #42850
Labels
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
dotnet-csharp/svc
lang-reference/subsvc
Pri2
Type of issue
Missing information
Description
There is a class of attributes interpreted by the compiler which could have its own page. I've seen them described as pseudo-custom attributes, or, as https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getcustomattributes describes them in the table it contains, simply pseudo-attributes. A pseudo-attribute is something that appears in C# syntax as an ordinary attribute, but upon compilation, it is not emitted into the IL custom attributes table as an ordinary attribute would be. Instead, IL flags or options are created. By making these IL options look like attributes, these options can be controlled using the C# language.
All of these may be used in C# source.
ComImportAttribute: maps to the IL
import
modifierDefaultParameterValueAttribute: maps to the default value for the parameter
DllImportAttribute: maps to the IL
pinvokeimpl
modifier, with various optionsFieldOffsetAttribute: maps to the offset for the IL
.field
InAttribute: maps to the IL
[in]
modifierMarshalAsAttribute: maps to the IL
marshal
modifier, with various optionsMethodImplAttribute: maps to the IL
flag
modifier, with specific named flags such asaggressiveinlining
orforwardref
, as well asnative
,managed
, oroptil
modifiers for the MethodCodeType field.NonSerializedAttribute: maps to the IL
notserialized
modifierOptionalAttribute: maps to the IL
[opt]
modifierOutAttribute: maps to the IL
[out]
modifierPreserveSigAttribute: maps to the IL
preservesig
modifierSerializableAttribute: maps to the IL
serializable
modifierSkipLocalsInitAttribute: maps to the absence of the IL
init
modifier for.locals
(This might belong here rather than in https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/general#skiplocalsinit-attribute. It's also the odd one out, where a custom attribute is also added to the compilation, but this may be considered an oversight and possibly corrected in the future.)SpecialNameAttribute maps the IL
specialname
modifierStructLayoutAttribute: maps to the IL
auto
,sequential
, orexplicit
modifiers, and some other optionsPage URL
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/general
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/attributes/general.md
Document Version Independent Id
6a60a627-c59c-74de-ce5b-6f52e15e7668
Article author
@BillWagner
Metadata
The text was updated successfully, but these errors were encountered: