I'm experimenting with C# source generation and I see references to Microsoft.CodeAnalysis.CustomModifier
in several places. For example, Microsoft.CodeAnalysis.IMethodSymbol
has a property RefCustomModifiers
.
The official documentation isn't particularly helpful, and searching the web hasn't turned up anything useful, either.
What C# feature (if any) is represented by a CustomModifier
?
I'm going to answer this myself to make it a little easier for someone searching for the same information.
As @HansPassant noted, custom modifiers are addressed by the CLI spec. Some highlights from the noted section:
II.7.1.1 modreq and modopt
Custom modifiers, defined using modreq (“required modifier”) and modopt (“optional modifier”), are similar to custom attributes (§II.21) except that modifiers are part of a signature rather than being attached to a declaration. Each modifer associates a type reference with an item in the signature.[snip]
For example, the const qualifier in the C programming language can be modelled with an optional modifier since the caller of a method that has a const-qualified parameter need not treat it in any special way. On the other hand, a parameter that shall be copy-constructed in C++ shall be marked with a required custom attribute since it is the caller who makes the copy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With