Currently I'm working in a tool that needs to create some sort of customized .NET with some additional fields. I've been wondering what approach is better to solve this, and been thinking in the following options:
Option A: - Create a derived class for each control (let's say, CLabel, CGroupBox...) where I define the new fields on each class. This would mean worse mantainability but would be easy to operate with.
Example:
class CLabel: Label
{
public List<Control> RelatedControls {get; set;}
public String textHint;
// more stuff...
public CLabel()
{}
}
Option B:
- This option would mean not creating a derived class from each control, but using the actual Label, GroupBox, etc controls and creating a class encapsulating all the "extra" properties. This extra properties object would be referenced in the Control.Tag
property. I have doubts about this one because referencing a sort of complex object inside the Tag
property feels a bit crappy to me, but this would mean better mantainability and also of course no need of subclassing controls.
Example:
Label lbl = new Label();
lbl.Tag = new ControlDescription();
Option C:
- This would mean having some sort of combination of Option A and B. Just creating the Custom Control, for example CLabel, that adds a type ControlDescription field to the Label control. This way we ensure encapsulation and mantainability, but we avoid the Tag
thing.
I'm pretty sure there are lots of options out there better than those. Probably just using polymorphism - a concept I still have problems with - the custom control classes could be taken away. What of those options do you think is the best one? Do you think that all of this could be better done?