Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get list of the classes in casual assembly
Message
From
12/03/2010 11:20:10
 
 
To
12/03/2010 09:25:19
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01453908
Message ID:
01454182
Views:
40
>>>>
>>>>My version returns a list Modules each containing a list of Classes. You'd need something like:
 List<IEnumerable<Type>> list = 
>>>> (from m in Assembly.Load(Assemblyname).GetModules() select m.GetTypes().Where(x => x.IsClass)).ToList();
>>>>
>>>>foreach ( IEnumerable<Type> t in list)
>>>>        {
>>>>              foreach (Type className in t)
>>>>              {
>>>>                 Console.WriteLine("{0}", className.FullName);
>>>>               }
>>>>        }
>>>
>>>
>>>Yes, I figured that out - see other message with AddRange() in GetModInfo()
>>
>>Oddly AddRange() was my first idea for modifying your original code:
public static List<Type> GetAssemblyClasses(string assemblyName)
>>        {
>>            var assembly = Assembly.Load(assemblyName);
>>            List<Type> classList = new List<Type>();
>>
>>            foreach (var module in assembly.GetModules())
>>            {
>>                classList.AddRange(from x in module.GetTypes().Where(x => x.IsClass) select x);
>>            }
>>            return classList;
>>        }
>
>
>Or without linq
>
>
>		public static List<Type> GetAssemblyClasses(string assemblyName)
>		{
>			var assembly = Assembly.Load(assemblyName);
>
>			List<Type> classList = new List<Type>();
>			foreach (var module in assembly.GetModules())
>			{
>				classList.AddRange(module.FindTypes(new TypeFilter(delegate(Type t, object o) { return t.IsClass; }), null));
>			}
>
>			return classList;
>		}
>
Ah - I didn't know the FindType() method was there. I even see there's a ready built TypeFilter for name ......
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform