Ten essential .NET development gadgets (6): Net Reflector
Author: James Avery translation: lucentoff
Source: http://msdn.microsoft.com/msdnmag/issues/04/07/musthavetools/default.aspx declaration: The copyright belongs to the original author, reproduced please indicate the source!
.NET Reflector
.NET Reflector is a class browser and an anti-compiler that checks the assembly and displays all of them. .NET Framework introduces the concept of reflection, using reflection to check any .NET-based code, whether a single class or a complete assembly. Reflection can also be used to retrieve information on various classes, methods, and attributes. Using the .NET Reflector, you can browse the class and method of the assembly, you can check the Microsoft Intermediate Language (MSIL) generated by these classes and methods, you can refine classes and methods, you can also view equivalent C # or Visual Basic? Net code.
In order to explain, I loaded the previous NUNITEXAMPLE assembly to the .NET Reflector, as shown in Figure 7.
Figure 7 Using .NET Reflecto View NUNITEXAMPLE assembly
With a variety of tools, .NET Reflector, you can further check this assembly. If you want to see MSIL that make up method, right click on the method and select "Disassembler" from the pop-up menu.
In addition to viewing MSIL, you can also view the C # code of the method under the Decompiler under the Tools menu. You can also view the method of refractory Visual Basic .NET or Delphi code by selecting the language menu. Below is the C # code generated by Net Reflector: public void hashtableaddtest ()
{
Hashtable hashtable1;
Hashtable1 = new hashtable ();
Hashtable1.add ("key1", "value1");
Hashtable1.add ("key2", "value2");
Assert.Arequal ("Value1", Hashtable1 ["Key1"],
"WRONG OBJECT RETURNED!");
Assert.Arequal ("Value2", Hashtable1 ["Key2"],
"WRONG OBJECT RETURNED!");
}
The above code and the actual code I have written are very similar, the following is the actual code: public void hashtableaddtest ()
{
Hashtable ht = new hashtable ();
Ht.Add ("Key1", "Value1");
HT.Add ("Key2", "Value2");
AskERT.Areequal ("Value1", HT ["Key1"],
"WRONG OBJECT RETURNED!");
AskERT.Areequal ("Value2", HT ["Key2"],
"WRONG OBJECT RETURNED!");
}
Although both are a bit different, the functionality is the same.
Although this example is used to display comparison and anti-compile code is a good way, I think .Net Reflector is the most useful of it to check the .NET Framework assembly and method. .NET Framework provides a number of ways to perform similar operations. For example, if you want to read a data set from an XML, you can use various methods such as XMLDocument, XPathnavigator or XmlReader. Using the .NET Reflector, you can see how Microsoft has written DataSet's READXML methods, or how to read data from the configuration file. .NET Reflector is also a good way to view the creation of objects such as httphandler or configuration handler, because you can see how the Microsoft development group actually builds these objects in .NET Framework. .NET Reflector is written by Lutz Roeder, download URL: http://www.aisto.com/roeder/dotnet.
[Translation: In the new version 4.0.10.0, the interface or operation is slightly different]