Reputation: 2438
Which version of .NET framework contains the keyword modopt?
Upvotes: 2
Views: 1674
Reputation: 942010
modopt is only used in IL. It is the job of a .NET language compiler to interpret and generate it. Ecma-335, Partition II, chapter 7.1.1 mentions it:
Custom modifiers, defined using modreq (“required modifier”) and modopt (“optional modifier”), are similar to custom attributes (§21) except that modifiers are part of a signature rather than being attached to a declaration.
[Rationale: The distinction between required and optional modifiers is important to tools other than the CLI that deal with the metadata, typically compilers and program analysers. A required modifier indicates that there is a special semantics to the modified item that should not be ignored, while an optional modifier can simply be ignored.
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. end rationale]
In other words, it allows adding metadata to declarations that do not matter to the CLR but do matter to the language. The C++/CLI compiler in particular uses it. Necessarily so, .NET has no equivalent for the const keyword for example.
Upvotes: 4
Reputation: 243096
I think that modopt
isn't an actual keyword in any .NET language (i.e. you cannot write modopt
in C#). It is a custom modifier generated by the C++/CLI compiler, which first appeared with .NET 2.0, so I suppose that modopt
has been added to .NET runtime at the same time.
Upvotes: 2