您的位置:首页 > 编程语言 > C#

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

2016-04-01 16:43 691 查看
1.引用

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: