Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a CustomModifier?

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?

like image 573
Jack A. Avatar asked Sep 20 '25 21:09

Jack A.


1 Answers

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.

like image 162
Jack A. Avatar answered Sep 22 '25 10:09

Jack A.