MSDN-WhiteKnight / CilTools

A set of tools to work with CIL in .NET applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Escape IL assembler keywords when used as identifiers

MSDN-WhiteKnight opened this issue · comments

CLI specification defines a set of keywords that must be escaped (enclosed into single or double quotes) when used as identifiers; for example: field, assembly. Methods that convert instructions/method signatures to text should be updated to escape them.

Example code:

using System;
using System.Reflection;
using CilBytecodeParser;

class Program
{
    public static void field()
    {
        Console.WriteLine("In the method 'field'...");
    }

    public static void Main(string[] args)
    {
        Console.WriteLine(CilAnalysis.MethodToText(typeof(Program).GetMethod("field")));        
        Console.ReadKey();
    }    
}

Current output:

 .method public hidebysig static void field() cil managed {
 .maxstack 8

          nop
          ldstr      "In the method 'field'..."
          call       void [mscorlib]System.Console::WriteLine(string)
          nop
          ret
}

Expected output:

 .method public hidebysig static void 'field'() cil managed {
 .maxstack 8

          nop
          ldstr      "In the method 'field'..."
          call       void [mscorlib]System.Console::WriteLine(string)
          nop
          ret
}

Ths list of keywords is defined in ECMA-335 Specification, section VI.C.1.