. NET CIL Series Third article: Positive and negative engineering

Source: Internet
Author: User

Having introduced the basics of CIL, we are now studying the actual use of CIL programming, starting with the pros and cons of the project.

Positive and negative to the project

It is already known that you can use Ildasm.exe to view the CIL code generated by the C # compiler (see the first article in the. NET CIL series: CIL introduction and Getting started), But maybe not. Ildasm.exe also allows you to export CIL in an assembly that is loaded into Ildasm.exe into an external file. Once you have CIL code, you can use the CIL compiler to ilasm.exe arbitrary edits or recompile code.

Description: Reflector.exe can be used to view CIL code for an assembly, or to translate CIL code into close C # code. However, if the assembly contains a CIL structure that does not have an equivalent C # implementation (C # and VB only implement a subset of all of the CIL attribute sets), we can only use Ildasm.exe.

This technique is called positive and negative engineering (round-trip-engineering), and it will be useful in the following cases.

n need to modify an assembly with no source code

n is in use. NET language compilers are not perfect enough to produce some inefficient CIL code that the user wishes to modify.

n Users build assemblies that can interoperate with COM and want to supplement those that are lost during conversion, such as COM's [helpstring] attributes.

To explain the process of positive and negative engineering, we use a text editor to create a new C # code file (HelloProgram.cs) and define the following classes (or you can use visual Studio 2008, but remember to delete AssemblyInfo.cs this file to reduce the number of CIL code generated):

// 简单的C#控制台程序

using System;

class Program

{

    static void Main(string[] args)

    {

        Console.WriteLine("Hello CIL code!");

        Console.ReadLine();

    }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.