首页 > 代码库 > 反射方法调用例子
反射方法调用例子
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 });
}
反射方法调用例子