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 08:40:12
 
 
To
12/03/2010 08:25:00
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01453908
Message ID:
01454145
Views:
26
>>
>>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;
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform