. Net programmers ten essential tools-. Net Reflector

Source: Internet
Author: User
Tags reflector
. Net Reflector

The next essential tool is. Net reflector. It is a class browser and anti-compiler that can analyze an assembly and show you all its secrets .. The Net Framework introduces reflection concepts that can be used to analyze any. Net-based code (whether it is a single class or a complete assembly) all over the world. Reflection can also be used to retrieve information about various types, methods, and attributes contained in a specific set of programs. Use. net reflector, you can browse the Assembly classes and methods, you can analyze the Microsoft intermediate language (msil) generated by these classes and methods ), in addition, you can decompile these classes and methods and view C # Or Visual Basic ?. . Net.

To demonstrate how. Net reflector works, I will load and analyze the nunitexample Assembly shown earlier. Displays the Assembly loaded in. Net reflector.

In. Net reflector, there are various tools available to further analyze the assembly. To view the msil that constitutes a method, click the method and select discycler from the menu.

In addition to msil, you can select decompiler under the Tools menu to view the C # format of this method. By changing your selection under the ages menu, you can also view the form in which this method is decompiled to Visual Basic. Net or Delphi. The code generated by. Net reflector is as follows:

public void HashtableAddTest()

    Hashtable hashtable1;
    hashtable1 = new Hashtable();
    hashtable1.Add("Key1", "Value1");
    hashtable1.Add("Key2", "Value2");
    Assert.AreEqual("Value1", hashtable1["Key1"], 
       "Wrong object returned!");
    Assert.AreEqual("Value2", hashtable1["Key2"],
       "Wrong object returned!");
}

The previous code looks like the code I actually wrote for this method. The actual code in this Assembly is as follows:

public void HashtableAddTest()
{
    Hashtable ht = new Hashtable();
            
    ht.Add("Key1", "Value1");
    ht.Add("Key2", "Value2");

    Assert.AreEqual("Value1", ht["Key1"],
        "Wrong object returned!");
    Assert.AreEqual("Value2", ht["Key2"],
        "Wrong object returned!");
}

Although there are some minor differences in the above Code, they are all functional in the same way.

Although this example is a good way to show the comparison between the actual code and the decompiled code, it does not represent to me. net reflector has the best use-analysis.. NET Framework Assembly and method .. . NET Framework provides many different methods to execute similar operations. For example, if you want to read a group of data from XML, there are multiple methods to do this using xmldocument, xpathnavigator, or xmlreader. By using. Net reflector, you can view what Microsoft uses when writing the dataset's readxml method, or what work they did when reading data from the configuration file .. Net reflector is also an excellent way to understand the following best implementation policies: creating objects such as httphandlers or configuring handlers, because you can understand how Microsoft workgroup actually generates these objects in the framework.

. Net reflector is written by Lutz roeder and can be downloaded from http://www.aisto.com/roeder/dotnet.

Go to the. NET programmer's ten essential tools-directory

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.