March 2020
Intermediate to advanced
534 pages
14h 15m
English
The code is split into three methods for readability and usability. It is always good practice to keep methods concise with a clear purpose.
The first method, SetControlLabel, will accept a FormControl object and a label in order to set its label property. FormControl is the base type for form controls, which is useful, but it does not contain the label property. We could write a method for each type of control, accepting a FormStringControl, FormRealControl, and so on, but this results in a lot of duplicated code.
In order to set the label property, we must check the control's type and then cast it, as shown in the following code:
if (_formControl is FormStringControl){ FormStringControl stringCtrl = _formControl; stringCtrl.label(_label); ...Read now
Unlock full access