反射方法调用例子
Posted huzige0265
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了反射方法调用例子相关的知识,希望对你有一定的参考价值。
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 });
}
以上是关于反射方法调用例子的主要内容,如果未能解决你的问题,请参考以下文章