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";
如何让我的代码工作?
答案 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}
}