c# - How to use reflection to find certain classes in an assembly? -


this question has answer here:

if have .net assembly loaded , want use reflection find classes (types) decorated attribute, eg

[myclassattribute] public someclass { }  

how do in c#? have got far

assembly assy = assembly.load(assypath); var classesinassy = assy.gettypes(); 

but thereafter i'm stumped. know have use customattibutes collection on type, i'm using vs2013 pro (which includes unit testing), , attribute in question isn't 1 of mine ms testclass attribute. can't seem reference assembly defined in (microsoft.visualstudio.qualitytools.unittestframework.dll) though dll listed in add references dialog in vs2013. missing something?

tia,

an alternative jon skeet's answer use getcustomattributes:

type[] classeswithattr = assy.gettypes()     .where(t => t.getcustomattributes(typeof(myclassattribute), false).length > 0)     .toarray(); 

Comments