c# - Get all User-Created Classes in AppDomain.CurrentDomain -


i want loop on classes have added in project

assembly[] foo = appdomain.currentdomain.getassemblies();  foreach(assembly in foo) {                     foreach(type t in a.gettypes())     {      } } 

this tried want exclude assemblies provided .net, example "mscorlib"

one common solution filter assemblies name, if of assemblies have common prefix (if have more or less unique prefix).

var foo = appdomain.currentdomain.getassemblies()                                  .where(a=>a.fullname.startswith("myproject.")); 

if interested in specific types, consider using attributes classes, or add 1 @ assembly level.

example:

create attribute:

[attributeusage(attributetargets.assembly)] public class myassemblyattribute : attribute { } 

add following assemblyinfo.cs:

[assembly: myassemblyattribute()] 

and filter assemblies looking at:

var foo = appdomain.currentdomain                    .getassemblies()                    .where(a => a.getcustomattributes(typeof(myassemblyattribute), false).any()); 

also find at question interesting. in one answer suggested check qualified name of each assembly, quite tedious, e.g.:

//add more .net bcl names necessary var systemnames = new hashset<string> {     "mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089",     "system.core, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"     ... };  var issystemtype = systemnames.contains(objtotest.gettype().assembly.fullname);  

it's easier mark assemblies (by name or attribute) trying identify ones part of .net framework.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -