码迷,mamicode.com
首页 > 其他好文 > 详细

反射方法调用例子

时间:2017-03-14 10:38:53      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:reflect   dfa   方法   cad   static   ber   load   private   lan   

private List<GetNewDateDTO> Reflection()
{
object obj;
Assembly assembly = Assembly.Load("NetGet.UI");//加载DLL,NetGet.UI 为类库名称
Type t = assembly.GetType("NetGet.UI.GetNewData.GetNewDataMastMVP.GetNewDataMastModel"); 

//不是静态方法需要用到这一部分
obj = t.InvokeMember(null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);


List<GetNewDateDTO> a;
a = (List<GetNewDateDTO>)t.InvokeMember("Query", BindingFlags.Public | BindingFlags.Instance |
BindingFlags.InvokeMethod, null, obj, new Object[] { "" });
return a;

}

public void LoadForm()
{


Assembly assembly = Assembly.Load("NetGet.UI");
Type t = assembly.GetType("NetGet.UI.FormLoadFacade");

var frm = CapitalAnalysisMast.ActiveForm;
t.InvokeMember("GetNewDataMastForm", BindingFlags.Public | BindingFlags.Instance |BindingFlags.Static|
BindingFlags.InvokeMethod, null, null, new Object[] { frm });
LoadData();

}

public void LoadData()
{
Assembly myAs = Assembly.Load("NetGet.UI");
Type T = myAs.GetType("NetGet.UI.GetNewData.GetNewDataListMVP.GetNewDataList");
object obj = T.InvokeMember(null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);

List<GetNewDateDTO> a=new List<GetNewDateDTO>();
a = Reflection();


T.InvokeMember("LoadData", BindingFlags.Public | BindingFlags.Instance |BindingFlags.NonPublic|
BindingFlags.InvokeMethod, null, obj, new Object[] { a });
}

反射方法调用例子

标签:reflect   dfa   方法   cad   static   ber   load   private   lan   

原文地址:http://www.cnblogs.com/huzige/p/6546912.html

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