Attributes recognized by the compiler in binaries #43110
Labels
doc-enhancement
Improve the current content [org][type][category]
dotnet-csharp/svc
lang-reference/subsvc
Pri2
Type of issue
Missing information
Description
As opposed to #43109, these attributes are generally disallowed in source. They affect the language meaning of compiled binaries, and thereby affect how the source code is compiled which references such binaries. This is of interest when using reflection or examining assemblies for purposes of understanding the language meaning of things in metadata.
It could also be interesting to list modreq and modopt types, which are not (usually) also attributes. They are part of the same theme as this page.
CompilerFeatureRequired - Prevents downlevel compilers from using metadata they can't safely understand.
DecimalConstantAttribute - Encodes
const decimal
fields since the runtime does not supportdecimal
values as constant values.DefaultMemberAttribute - Encodes indexers with IndexerNameAttribute. This is how the correct indexer is recognized as default when its name has been customized. Allowed in source.
DynamicAttribute - Encodes whether a type in a signature is
dynamic
(versusobject
).Microsoft.CodeAnalysis.EmbeddedAttribute
- Types annotated with this attribute are ignored during lookup by the C# compiler. The compiler applies this to types that it generates as internal when compiling. This keeps the generated internal types from affecting other compilations when InternalsVisibleTo is used. Always generated, not in BCL. (References: Generate readonlyattribute if it does not exist roslyn#18715, React to attribute centralization roslyn#68697 (comment))ExtensionAttribute - Encodes extension methods, and is also placed on their containing classes.
FixedBufferAttribute - Encodes
fixed
struct fields.IsByRefLikeAttribute - Encodes a
ref
struct.IsReadOnlyAttribute - Indicates whether a parameter is
in
(versusreadonly ref
or[In] ref
).IsUnmanagedAttribute - Encodes an
unmanaged
constraint on a type parameter.NativeIntegerAttribute - Encodes
nint
/nuint
when runtime doesn't supportnative int
. Always generated, not in BCL: Add NativeIntegerAttribute runtime#38683.NullableAttribute, NullableContextAttribute, NullablePublicOnlyAttribute - Encode nullability annotations.
ParamArrayAttribute - Encodes
params
on array parameters.ParamCollectionAttribute - Encodes
params
on non-array parameters. Part of the params collections language feature.RefSafetyRulesAttribute - Encodes a version that is required in order to understand ref safety annotations in the assembly. Part of the low-level struct improvements language feature.
RequiredMemberAttribute - Encodes
required
on a member. Part of the required members language feature.RequiresLocationAttribute - Encodes whether a parameter is
readonly ref
(versusin
or[In] ref
).TupleElementNamesAttribute - Encodes tuple element names used in signatures.
Page 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
Related Issues
The text was updated successfully, but these errors were encountered: