Getting started with Reflector Addins

If you are just thinking you want to write a Reflector addin, you should first look at Introduction to the .NET Reflector Add-In Model.

Here is a very basic walk through creating a simple addin and steps to get it stopped in the debugger:

1.  Open a new VS 2005 dll project

2.  Give it some name (I used 'TestPackage')

3.  Set a reference to your local Reflector.exe

4.  Paste the following code into the class

using System;
using Reflector;
using Reflector.CodeModel;
 
namespace Reflector.Addin
{
    public class TestPackage : IPackage
    {
 
        private IServiceProvider serviceProvider;
        private ICommandBarManager commandBarManager;
        private ICommandBarSeparator separator;
        private ICommandBarButton button;
 
        public void Load(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
 
            AddButton();
        }
 
        public void Unload()
        {
            RemoveButton();
        }
 
        private void Button_Click(object sender, EventArgs e)
        {
            ProcessClick();    
        }
 
        private void ProcessClick()
        {
            IAssemblyBrowser assemblyBrowser = GetService<IAssemblyBrowser>();
            IWindowManager windowManager = GetService<IWindowManager>();
            ICommandBarManager commandBarManager = GetService<ICommandBarManager>();
            IConfigurationManager configurationManager = GetService<IConfigurationManager>();
            IAssemblyManager assemblyManager = GetService<IAssemblyManager>();
            ILanguageManager languageManager = GetService<ILanguageManager>();
 
            System.Diagnostics.Debugger.Break();
 
        }
 
        private void AddButton()
        {
            this.commandBarManager = GetService<ICommandBarManager>();
            this.separator = this.commandBarManager.CommandBars["Tools"].Items.AddSeparator();
            this.button = this.commandBarManager.CommandBars["Tools"].Items.AddButton("Stop"
                new EventHandler(this.Button_Click));
        }
 
        private void RemoveButton()
        {
            this.commandBarManager.CommandBars["Tools"].Items.Remove(this.separator);
            this.commandBarManager.CommandBars["Tools"].Items.Remove(this.button);
        }
 
        private T GetService<T>()
        {
            return (T)serviceProvider.GetService(typeof(T));
        }
    }
}

5. Compile and run the Reflector.exe that is in the bin directory

6. Go to the View->Add ins ... dialog

7. Click Add ... button and find your dll you just built and choose it

8.  Click Close

9.  Go to the Tools menu, you should now see a Stop item

 image

10.  Click Stop and wait for the dialog below to show

image

11.  Click Debug, you'll then see the following debugger dialog:

image

12.  Choose the project that you just created and compiled

13.  Once you get the 'no source code available' dialog, click Ok and hit F10

image

You are now ready to explore the objects in the ProcessClick() method ... have fun :) 

BTW:  The quickest way to kill Reflector, if needed, is through task manager

posted on Tuesday, October 30, 2007 8:11 PM

Feedback

# Links from the Sharpside [10.30.07]

Links from the Sharpside [10.30.07]
10/30/2007 9:48 PM | Tales from the SharpSide

# Link Listing - October 31, 2007

AJAX JSON in ASP.NET Ajax: Part 3. Server side deserialization and elaboration of JSON data returned...
11/1/2007 12:05 AM | Christopher Steen

# Reflector Add-in Starter Kit (C#)

3/31/2008 6:59 PM | Jason Haley

Post Comment

Title  
Name  
Url
Comment   
Please enter the following code into the box below to stop spammers

  
Enter Code Here *