How can I find out all the references for the current project and tell which ones are derived from a specific base class in C #?
Due to a policy in a very large financial institution I work for, I cannot use the Castle Project ActiveRecord implementation, but as with the template, I implemented it myself. This is complete and the guide is now looking for a GUI tool to view all activerecord classes, find instances, and manipulate data.
To this end, I create a "browser" that iterates over all the classes in the referenced project, and if they are derived from the partiular base class ("ActiveInstanceBase"), make them validate and modify in the ASP.NET datagrid.
The first step for me is figuring out how to iterate over 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 to populate the type dropdown to check.
-
How can I get a list of all links for the current project? Google doesn't do something for me on the first page of results for multiple queries. I get a lot of information about writing Visual Studio add-ins, but I don't check anything at runtime.
-
How to determine the base class of a derived type at runtime if the base class takes a type parameter?
if (t.IsSubclassOf (typeof (ActiveInstance.ActiveInstanceBase))) {}
The syntax is not correct and I cannot know t at runtime.
I am also forced to use IE6, so I apologize if this post is not well formatted. Thank you very much in advance!
a source to share
1) How to get the assemblies specified 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 ...
a source to share