views:

78

answers:

2

Due to politics at the very large finanial institution for which I work, I am not able to use Castle Project's ActiveRecord implementation, but like the pattern so much I have implemented it myself. This is complete, and now management is looking for a GUI tool to browse all the activerecord classes, search for instances and manage data.

To this end, I'm building a "browser" that iterates through all the classes in a referenced project, and if they are derived from a partiular base class ("ActiveInstanceBase"), make them available for inspection and modification in an ASP.net datagrid.

The first step for me is to figure out how to iterate through all the references in the current project (developers using this tool will add their dlls to the project as references) and identify the ActiveInstance classes in order to fill a dropdown full of types to inspect.

  1. How do I get a list of all the references for a current project? Google is not turning anything up for me on the first page of results for a number of queries. I'm getting a lot of stuff about writing Visual Studio addins, but nothing for runtime inspection.

  2. How do I determine the base class of a derived type at runtime if the base class takes a Type parameter?

if (t.IsSubclassOf(typeof(ActiveInstance.ActiveInstanceBase))) {}

Isn't the proper syntax, and I can't know t at runtime.

I'm also forced to use IE6, so pardon if this post is not very well-formatted. Thanks very much in advance!

+1  A: 

1) How to get the assemblies referenced in your project

Assembly ourAssembly = Assembly.GetEntryAssembly();
AssemblyName[] refs = ourAssembly.GetReferencedAssemblies();

2) Use Type.IsSubclassOf() or Type.GetInterface()

Type theType = typeof(ActiveInstance.ActiveInstanceBase<>);
foreach(Type type in assembly.GetTypes())
{
    if (type.IsSubclassOf(theType))
    { ... }
}

Those should work for you...

Reed Copsey
What about if theType requires a Type parameter a la ActiveRecord?"MyClass : TheType<T>"
Chris McCall
whoops that should be "MyClass : TheType<MyClass>"
Chris McCall
Type t = typeof(TheType<>); The rest stays the same.
Reed Copsey
I edited to display
Reed Copsey
A: 

if you have political rules against downloading third party software, this may not work, but I use .net Reflector. It will give you the references and decompile the code for reviewing.

http://www.red-gate.com/products/reflector/

dsrekab