我正在自动生成代码,根据配置创建一个winform对话框(包含文本框、日期选择等)。这些对话框中的控件是从已保存的数据集中填充的,需要为各个控件对象(自定义或其他)设置和获取属性。
现在这很好,但是只读属性怎么办?我希望保存属性的结果,但需要知道何时不生成试图填充它的代码。
//Upon opening of form - populate control properties with saved values
MyObject.Value = DataSource.GetValue("Value");
//Upon closing of form, save values of control properties to dataset.
DataSource.SetValue("Value") = MyObject.Value;
现在这很好,但是只读属性怎么办?我希望保存属性的结果,但需要知道何时不生成试图填充它的代码。
//Open form, attempt to populate control properties.
//Code that will result in 'cannot be assigned to -- it is read only'
MyObject.HasValue = DataSource.GetValue("HasValue");
MyObject.DerivedValue = DataSource.GetValue("Total_SC2_1v1_Wins");
//Closing of form, save values.
DataSource.SetValue("HasValue") = MyObject.HasValue;
请记住,直到运行时我才知道我实例化的对象类型。
如何在运行时识别只读属性?