码迷,mamicode.com
首页 > Windows程序 > 详细

C#反射

时间:2014-12-24 17:52:53      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

Assembly assembly = Assembly.Load("project");
Assembly assembly2 = Assembly.LoadFrom("project.dll");

技术分享

Module[] module = assembly.GetModules();
foreach (Module item in module)
{
Console.WriteLine("module:" + item);

}

//获取namespace,class

Type[] types = assembly.GetTypes();

foreach (Type item in types)
{
Console.WriteLine("type:" + item);
Type t = item;
MethodInfo[] methods = t.GetMethods();
IEnumerable<MethodInfo> methodInfo = t.GetRuntimeMethods();
foreach (MethodInfo methodInfoitem in methodInfo)
{
Console.WriteLine("\t\t\tmethodInfoitem:" + methodInfoitem);
}
Console.WriteLine();
foreach (var items in t.BaseType.GetMembers())
{
Console.WriteLine("BaseType:" + items);
}
foreach (MethodInfo method in methods)
{
Console.WriteLine("方法:" + method);
Type typeopen = assembly.GetType(Convert.ToString(item));
var user12 = Activator.CreateInstance(typeopen);
string chuan = Convert.ToString(method);
string strs = chuan.Substring(chuan.IndexOf(" ") + 1, chuan.Length - chuan.IndexOf(" ") - 1);
strs = strs.Substring(0, strs.IndexOf("("));
if (strs == "PublicShow")
{

typeopen.InvokeMember(strs,
BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, user12,
null);

}

}
}

C#反射

标签:

原文地址:http://www.cnblogs.com/Show-shi/p/4182727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!