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

C#学习(9):通过反射设置泛型类型的属性及值

时间:2016-04-01 17:37:54      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:

1.引用

1 IResult result = ExecuteDmsParam<DMSParam, ORD_PurchaseParam>(dmsParam, purchaseParam, "HQBuy.MVC.BLL.Member.ORD.ORD_PurchaseBLL", "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, "HQBuy.MVC.BLL.Member.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#学习(9):通过反射设置泛型类型的属性及值

标签:

原文地址:http://www.cnblogs.com/wzk153/p/5345440.html

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