[NET]. NET programmers ten essential tools-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.

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.