AssemblyReflector, along with Microsoft SDC TaskBuilder represent the fruits of my Xmas holiday hobby coding; I'm one of these unfortunate people who just can't turn off their brain and stop new ideas from coming even when they are suppose to be relaxing and taking a break from the work they do all year round.
AssemblyReflector (Conchango.Code.Reflection) is an event-based assembly parser - it allows assemblies to be searched for: Attributes, Events, Fields, Interfaces, Methods, Nested Types, Properties and Types, by subscribing to the relevent OnDiscover event and then performing a search for the member based on several available search methods;
- Contains(string)
- EndsWith(string)
- Named(string)
- OfType(Type) - Attributes Only
- StartsWith(string)
- WithBindingFlags(BindingFlags)
When an event is raised you can access the discovered member via the EventArgs.
I've uploaded AssemblyReflector v1.0.0.0 to my Projects Page on Darren Neimke's awesome ProjectDistributor site - where you can download the Source or the Binaries for the class library. The Source contains the AssemblyReflector project, a demo console application project, a test assembly project and a partially completed unit test suite.
In order for the demo application to work you will need to ensure that you have NUnit installed - as the TestAssembly uses the NUnit.Framework.TestAttribute and NUnit.Framework.TestFixtureAttribute.
Demo:
Once you have downloaded the Source or the Binaries; In a command prompt execute Conchango.Code.Reflection.Demo.exe - you will be presented with some information and 6 different searches you can perform on the Conchango.Code.Reflection.TestAssembly.dll:

Select a number (1-6) and then hit enter. The specified search will run and the results will be outputted to the console window. To verify that the correct members have been found - look at Conchango.Code.Reflection.TestAssembly.cs (in the Binaries zip or Conchango.Code.Reflection.TestAssembly\TestTheOneRing.cs in the Source zip)- this is the source of Conchango.Code.Reflection.TestAssembly.dll.
Example of how to use AssemblyReflector:
Create a new class called simple.cs and paste the following in:
//---------------------------------------------------------------------------------------------------
//
// Copyright © 2005 Conchango Plc. All rights reserved. NO WARRANTY
// BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE
// EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
// HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
// EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
// PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
// SERVICING, REPAIR OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
// WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
// PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
// INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
// (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
// SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
// PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGES.
//
// Permission is granted to anyone to use this software for any purpose, including commercial
// applications, and to alter it and redistribute it freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
// original software. If you use this software in a product, an acknowledgment in the product
// documentation would be appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
// being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
//
//
// File Created
//
//---------------------------------------------------------------------------------------------------
namespace Conchango.Code.Reflection.Demo
{
#region Directives
using System;
using Conchango.Code.Reflection;
using Conchango.Code.Reflection.EventArgs;
#endregion
///
/// A simple example of how to use AssemblyReflector
///
public class Simple
{
private AssemblyReflector reflector;
///
/// Main entry point the the application.
///
///
string arguments passed into the application - not used
[STAThread]
public static void Main(string[] args)
{
Simple simpleDemo = new Simple();
Console.ReadLine();
}
///
/// Creates a new instance of the Simple object - wires up AssemblyReflector events and performs
/// a search for all methods in Conchango.Code.Reflection.TestAssembly.dll that start with the
/// word "IsAlso" and writes out the results to the console window.
///
public Simple()
{
this.reflector = new AssemblyReflector();
//Wire up events you want to display
this.reflector.OnAssemblyLoadFailure += new AssemblyReflector.AssemblyLoadFailureEventHandler(OnAssemblyLoadFailure);
this.reflector.OnMethodDiscovered += new AssemblyReflector.MethodDiscoveredEventHandler(OnMethodDiscovered);
//Load the test assembly
this.reflector.Assemblies.Load("Conchango.Code.Reflection.TestAssembly.dll");
//Find all methods in the test assembly that start with the word "IsAlso"
this.reflector.Methods.StartsWith("IsAlso");
}
///
/// Writes a message out to the console when an assembly fails to load successfully
///
///
The source of the event.
///
A AssemblyEventArgs that contains the event data.
private void OnAssemblyLoadFailure(object sender, AssemblyEventArgs e)
{
Console.WriteLine(string.Format("Assembly: {0}, failed to load", (e.Message)));
}
///
/// Writes a message out to the console when a method matching the search parameters is found
///
///
The source of the event.
///
A MethodInfoEventArgs that contains the event data.
private void OnMethodDiscovered(object sender, MethodInfoEventArgs e)
{
Console.WriteLine("Method " + e.Method.Name + " discovered.");
}
}
}
You will need to add a reference to both Conchango.Code.Reflection.dll and Conchango.Code.Reflection.TestAssembly.dll.
In the example above the TestAssembly is loaded and a search is performed for all methods that start with the word "IsAlso". The console window output should show the following:
