Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get list of the classes in casual assembly
Message
From
11/03/2010 11:44:09
 
 
To
11/03/2010 09:30:04
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01453908
Message ID:
01453948
Views:
50
>>I need to get list of classes names from any taken particular assembly by code
>>For example for system.windows.forms
>>The assymbly name should be entry method parameter
>>I tried to write this method using my old samples of using reflection for getting list of methods, events , properties
>>
>>public string GetModInfo(string Assemblyname)
>>
>>{
>>
>>Assembly a = Assembly.LoadWithPartialName(Assemblyname);
>>
>>** This string now gives error - this is old method of load, code is depricated
>>** use load instead ???
>>**
>>Module M = a.GetModules();
>>** this also gives error
>>Type T = M.GetType();
>>for each( ....
>>
>>*********************************************************
>>I looked many samples of using reflection on different sites and did not find the code
>
>
>Vladimir,
>
>Would this give you a start ?
>
>
>
>		static void Main()
>		{
>
>			var list = GetAssemblyClasses("GregoryAdam.Base");
>
>			foreach (var className in list)
>			{
>				Console.WriteLine("{0} : {1}", className.IsClass ? "Class" : "Struct", className.FullName);
>			}
>			Console.ReadLine();
>
>		}
>		public static List<Type> GetAssemblyClasses(string assemblyName)
>		{
>			var assembly = Assembly.Load(assemblyName);
>
>			List<Type> classList = new List<Type>();
>
>
>			foreach (var module in assembly.GetModules())
>			{
>
>				foreach (var type in module.GetTypes())
>				{
>					// only interested in classes or struct
>					if (!type.IsClass ) // && !type.IsValueType)
>						continue;
>
>					classList.Add(type);
>				}
>			}
>
>			return classList;
>		}
>
>	}
>
or:
var list = (from m in Assembly.Load("GregoryAdam.Base").GetModules() select m.GetTypes().Where(x=>x.IsClass)).ToList();
Not as flat though :={
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform