I have the following method:
public static Type[] GetAllClasses(this Assembly assembly)
{
var types= assembly.GetExportedTypes().Where(x=>x.IsClass).OrderBy(x=>x.Name).ToArray();
return types;
}
I would like to exclude all types that are collections .How can I do that?
When debugging I can see that collection have a baseType"List'1".How can I trap that and exclude those?
many thanks
This might work...
var types= assembly.GetExportedTypes()
.Where(x=>x.IsClass && x.GetInterface("IEnumerable")==null)
.OrderBy(x=>x.Name).ToArray();
(Or use the more specific collection interfaces - IList or ICollection if you want to exclude those)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.