【发布时间】:2013-03-11 02:12:39
【问题描述】:
首先,我不喜欢编程,但可以弄清楚基本概念 满足我的需要。
在下面的代码中,我想按名称“Gold”设置属性,如下所示:
_cotreport.Contract = COTReportHelper.ContractType."Blabalbal"
protected override void OnBarUpdate()
{
COTReport _cotreport = COTReport(Input);
_cotreport.Contract=COTReportHelper.ContractType.Gold;
_cotreport.OpenInterestDisplay=COTReportHelper.OpenInterestDisplayType.NetPosition;
double index = _cotreport.Commercial[0];
OwnSMA.Set(index);
}
我尝试了下面的代码,但系统说:“
对象引用未设置为对象的实例”
请帮忙!
System.Reflection.PropertyInfo PropertyInfo = _cotreport.GetType().GetProperty("ContractType");
PropertyInfo.SetValue(_cotreport.Contract,"Gold",null);
PropertyInfo.SetValue(_cotreport.Contract,Convert.ChangeType("Gold",PropertyInfo.PropertyType),null);
【问题讨论】:
-
提问前先打谷歌
-
“打码”?不错...
标签: c# dynamic reflection properties set