Search code examples
.netmono.cecil

Is there a way in Mono.Cecil to determine that a MethodDefinition is actually a C# operator without parsing the name?


I want to avoid parsing the name, like op_Equality. Is there another way to determine if the given MethodDefinition is actually an operator?


Solution

  • Not that I am aware of;

    Section I.10.3 of ECMA-335 states:

    Operator overloading is described by using the names specified below, and by setting a special
    bit in the metadata (SpecialName) so that they do not collide with the user’s name space. A
    CLS-compliant producer tool shall provide some means for setting this bit. If these names are
    used, they shall have precisely the semantics described here
    

    followed by a list of such special names (for instance for binary operators ).

    That said, since all operators need to be marked as specialname it is possible to quick check whether a method definition may be an operator.