I create automatically generated code that creates a winform dialog based on the configuration (text fields, dateTimePickers, etc.). The controls in these dialogs are populated from the saved dataset and
it is necessary to set and get properties for various control objects (custom or others).
//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;
Now everything is fine, but what of the readOnly properties? I want to save the result of a property, but you need to know when to NOT generate code that will try to populate it.
//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;
Remember that I do not know the type of object that I created before execution.
How can I (at runtime) identify the readonly property?
c # properties
Moslo
source share