首先,我不喜欢编程,但可以根据我的需要找出基本概念。
在下面的代码中,我想按名称“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);