Department of InformatiX
Microsoft .NET Micro Framework Tools & Resources

Update July 2018: .NET Reflector is no longer free since 2011. I recommend ILSpy instead.

Reflector is an essential tool for every .NET developer. It not only allows you to display the source code of .NET assemblies (in most cases), but also allows you to search any class or member, inspect the possibilities of a framework or helps you to understand the compilation process. The great thing is that you can use it with .NET Micro Framework as well.

Installing the Lutz Roeder's .NET Reflector

  1. Download the latest version here.
  2. Extract the archive in any folder and run the Reflector.exe (the application runs without installation):
    Screenshot of Reflector's first run
  3. If you want to explore a .NET Framework, select a version to start with, or just press Cancel.
  4. From the File menu choose Open List... (or press Ctrl+L).
  5. Press the Add button and type .NET Micro Framework or whatever you like:
    Assembly List Management
  6. When you are finished typing, press Enter and Select button. You will be presented with the same list as in the second point. Now press Cancel.
  7. From File menu choose Open... (or press Ctrl+O). Navigate to the Assemblies folder of where you have installed the .NET Micro Framework SDK, like C:\Program Files\Microsoft .NET Micro Framework\v2.5\Assemblies, select all files (or press Ctrl+A) and press Open. Now you will see list of all .NET Micro Framework assemblies, which should look like this:
    .NET Micro Framework 2.5 assemblies loaded

The last four steps can be repeated to open different version of the framework if you like. You can then switch between the lists using File | Open List... or Ctrl+L.

Common tasks

Most people use Reflector to see the source code of an assembly. In .NET Micro Framework however, pretty much is handled in CLR or at lower layer, which can't be viewed using Reflector. Such methods are marked as extern. For example, expand the tree to navigate to Microsoft.SPOT.Hardware > Microsoft.SPOT.Hardware.dll > Microsoft.SPOT.Hardware > OutputPort > Write(Boolean) : Void. You can see it is declared as public extern in the summary window under the tree. That means that this method has native implementation - indeed, different processors can have different ways to write value on its pins.

Exploring the source code

However, there are parts of the framework, which are completely managed, like for example the DPWS libraries, or the WPF controls. Let's see: navigate to Microsoft.SPOT.TinyCore > Microsoft.SPOT.Tinycore.dll > Microsoft.SPOT.Presentation.Controls > Border. Now to see its implementation, press space bar or choose Disassemble from Tools menu. The Reflector's window will expand and you will see Border's member signatures:

Disassembler window for Border

If you click the Expand Methods words, you will see complete source code of the class which you can copy and paste into your project. Or you can expand the tree and click individual members to see their implementation. Clicking on anything in the source code window will bring you to its declaration, so you can visually step through the code.

Note: Normal constructors are shown as .ctor and static ones as ..ctor. Gray text represents types or members which are not public (i.e. you can't use them in you project directly).

Searching for a class or member

If you are looking for a particular object, you can click View | Search (or press F3). A Search window will be opened in which you can type what you are looking for. You will be presented a list of all items which contain your keyword either in name, or in its namespace. You can use space to specify more keywords you all want the item to contain:

Searching for 'dpws handler'

As you can see you can use this not only to find a type in a namespace or list all members of a namespace across all assemblies, but also to find out in which assembly the type is, so that you can reference it in your project. To search in member names (like methods or properties), select the property icon (or press Ctrl+M). Double clicking on the result will open it in the tree view.

Discovering the inheritance chain

You might also want to know all the ascendants of your type, or which classes derives from it. For example, to find out what panels does the .NET Micro Framework ship with, navigate to Microsoft.SPOT.TinyCore > Microsoft.SPOT.TinyCore.dll > Microsoft.SPOT.Presentation.Controls > Panel > Derived Types (or just search for 'panel' and double click it):

Panel inheritors

Not much, is it? :)

Analyzer

Another useful trick is to determine from where is some particular method called. This can be done using Analyzer. Let's analyze the System.Ext.Guid type in MFDpwsExtensions assembly. Click on it using right button/open the Tools menu and choose Analyze (or press Ctrl+R).

Analyzer

Namespace view

If you prefer to browse through the framework by namespaces, go to the View menu and select Options.... In the Browser section check Flatten namespaces. That way you will see all types in a namespace:

Flattened namespaces

All of the classes above are from the Microsoft.SPOT.Hardware assembly except the ScreenMetrics from Microsoft.SPOT.Graphics and SystemID and Utility which are from the Microsoft.SPOT.Native assembly as you can see in the summary window.

Answering your questions

Which reference should I add to use the System.Ext namespace?

We don't know the exact type one is looking for, but if you search for 'system.ext', you will see that everything in this namespace comes from MFDpwsExtensions assembly.

Is there any guid type?

Well you've found that there is no System.Guid. Though, if you search for 'guid', you will find one in the System.Ext namespace.

How do I set the correct time zone?

So we use TimeZone.CurrentTimeZone to get the zone, but this property is read only. Searching for 'timezone' in types doesn't help, but when you switch to members search, you can see the right method. Or if you know what you are looking for, you can try to search members for 'set timezone', which gives you all methods you could ever need to use.

Do I have to call Invalidate() from UI thread?

Let's see what this method does. Search members for 'invalidate' (use the property icon). If you use the equality icon to return only exact matches, it is the only one returned. Otherwise, choose the Invalidate method of UIElement. Double click on it to open locate the method in the tree. Press space to show the disassembly (source code). There is only one line in it - a call to PropagateFlags method. Click on it to see its code. You will find it calls the MediaContext.PostRender() method. Again, click on the words PostRender. And here we go, there is a call to Dispatcher.BeginInvoke, which means, the rendering is queued on the dispatcher thread so you can call Invalidate() from any thread you like.

I hope this intro will help you learn something new and that you will be able to answer some of your questions yourself!

PS: Adding to Visual Studio

You can start the Reflector directly from Visual Studio. Click on Tools menu, External Tools.... Press Add button. Type .NET &Reflector in the Title box and locate your Reflector.exe after pressing the ... button next to the Command box. Now you can press Alt+T, R (or click it in the Tools menu) anytime and the Reflector will start. I even start Visual Studio just to run the Reflector! ;-)

Comments
Sign in using Live ID to be able to post comments.