//Assembly[] asms= AppDomain.CurrentDomain.GetAssemblies();//获取程序集
//foreach (Assembly asm in asms)
//{
// Console.WriteLine(asm.Location);
//}
string path=@"D:\net实例教程\练习net\程序集与反射\程序集测试1\bin\Debug\程序集测试1.dll";
Assembly asm=Assembly.LoadFile(path);//加载程序集
Type[] types = asm.GetTypes();//获取类的描述
foreach(Type type in types)
{
Console.WriteLine(type);
FieldInfo[] infos = type.GetFields();
foreach( FieldInfo f in infos )//遍历字段
{
Console.WriteLine(f);
}
PropertyInfo[] pinfo = type.GetProperties();
foreach (PropertyInfo f in pinfo)//遍历属性
{
Console.WriteLine(f);
}
MethodInfo[] minfo=type.GetMethods();
foreach (MethodInfo f in minfo)//遍历方法
{
Console.WriteLine(f);
}
Type t1 = asm.GetExportedTypes()[0];//获取第一个
object obj1 = Activator.CreateInstance(t1);//new 一个实例