This add-in allows you to rectify the code generated by Reflector, a well known decompiler which converts the MSIL to C# or VB.NET source code. Sometimes the generated code is not compilable because the produced code is not in the form of C# or any other .NET language.
Using this add-in we can make the code compilable by replacing with the correct code for events and properties. Currently this supports the following tasks (it works only for C# code):
- Replace the (wrong) methods with properties.
- Replace the (wrong) methods with events.
Where the Reflector makes mistake
When a class implements an interface, while the interface has properties or events, we face a problem using the reflector. For example,
TypeView class in
Microsoft.Matrix.Packages.ClassView implements the interface
IDocumentView, which has a property
CanDeactivate and an event
DocumentChanged with other members.
The wrongly generated code looks like this:
void IDocumentView.add_DocumentChanged(EventHandler value)
The right code
The following correct code can be produced by the add-in:
For the event:
public event EventHandler DocumentChanged;
For the property:
How it works
When you select the (wrong) method and right-click, the 'Replace the Method' menu item will appear. When selecting the menu, it takes the method and decides whether it should be converted either to property or event using these methods.
If get_ or set_ is part of the method, then it is a property.
private bool IsProperty(string signature)
if ((signature.IndexOf("get_") >=0)||
(signature.IndexOf("set_") >=0)) return true;
If add_ or remove_ is part of the method, then it is an event.
private bool IsEvent(string signature)
if ((signature.IndexOf("add_") >=0)||
(signature.IndexOf("remove_") >=0)) return true;
Based on the result, the property or event will be manipulated and inserted above the current location in the editor. The wrong code will be commented.
Points of Interest
I am doing loot string handling to achieve this. I am not able to get the function body from the Code Function. I have to find out a better way to manipulate and get the function body.
- Currently it supports only C# source code.
- While commenting the wrong code, the line indent is changing.
- The inserted code sometimes is not indented correctly.
This is the first version - 1.0.
The DSWatch and GhostDoc add-ins were very helpful in coding this add-in.