C#学习(9):通过反射设置泛型类型的属性及值
2016-04-01 16:43
691 查看
1.引用
2.方法
IResult result = ExecuteDmsParam<DMSParam, ORD_PurchaseParam>(dmsParam, purchaseParam, "BLL", "GetPurchaseByPNO");
2.方法
public IResult ExecuteDmsParam<T1, T2>(T1 t1, T2 t2, string ClassName, string MethodName) { Type type = t1.GetType(); if (type.GetProperties() != null && type.GetProperties().Length > 0) { foreach (var propertie in type.GetProperties()) { if (!string.IsNullOrEmpty(propertie.Name)) { switch (propertie.Name) { case "AssemblyName": t1.GetType().GetProperty(propertie.Name).SetValue(t1, "BLL.dll"); break; case "ClassName": t1.GetType().GetProperty(propertie.Name).SetValue(t1, ClassName); break; case "MethodName": t1.GetType().GetProperty(propertie.Name).SetValue(t1, MethodName); break; case "Param": t1.GetType().GetProperty(propertie.Name).SetValue(t1, t2); break; } } } } IResult result = ExecuteBLL.Execute((IParam)t1); if(result.Complete == DMSComplete.Succeed) { ConditionResult<ORD_Purchase> purchaseCondition = new ConditionResult<ORD_Purchase>(); if (result.Result != null) { purchaseCondition = (ConditionResult<ORD_Purchase>)result.Result; List<ORD_Purchase> purchaseList = (purchaseCondition).ResultList; } } return result; }
相关文章推荐
- C#大文件读取和查询--内存映射
- C#中axWindowsMediaPlayer控件的用法
- C#中,switch case语句中多个值匹配一个代码块的写法
- C# 清空sessin
- C# Dictionary用法总结
- C# ——输入 若干字符组成的字符串,写静态方法,统计并输出各种字符的数目
- C#装箱与拆箱
- c# 最简单的线程
- C#基本语法学习(十)
- C# this 关键字
- c#中委托与多线程的实质
- 2016-4-1--C#泛型
- 【转】C# 开发Chrome内核浏览器(WebKit.net)
- [C#]自定义消息收发
- C#小知识点
- C#中类型分析中的常见问题 Type
- C# --数组
- C# 特性详解
- C#winform如何最小化主窗口
- C# 元数据描述