如何在C#中设置thirdlevel属性

时间:2015-12-24 23:45:16

标签: c# properties

string sObjectValue="Caption";
PropertyInfo mainProperty= grdData.GetType().GetProperty("MasterTableView");
PropertyInfo subProperty1= mainProperty.PropertyType.GetProperty("EditFormSettings");
PropertyInfo subProperty2= subProperty1.PropertyType.GetProperty("InsertCaption");

subProperty2.SetValue(subProperty1, sObjectValue); //ERROR : Object does not match target type.

这里grdData是RadGrid, 我想设置第三级属性,如:

grdData.MasterTableView.EditFormSettings.InsertCaption = "Caption";

如何让我的代码工作?

1 个答案:

答案 0 :(得分:0)

尝试

PropertyInfo MasterTableView  => grdData.GetType().GetProperty("MasterTableView);
PropertyInfo EditFormSettings => MasterTableView.PropertyType.GetProperty("EditFormSettings");
PropertyInfo InsertCaption 
{
    get { return EditFormSettings.Property.GetProperty("InsertCaption");
    set { EditFormSettings.Property.GetProperty("InsertCaption") = value}
}