I have multiple classes that will store similar data for different uses and I simply would like them to be based of the same base class and serialize all the data to XML however I wish to change the Element Names when it serializes. This is in C#.
I want to use the Class names to make it easier to read my code and simpler to implement.
public BaseMenuItem
{
public string ItemName;
public string ItemDescription
public string ItemAssetName;
public List<BaseMenuItem> SubMenuItems;
}
then have other items inherit this and serialize it with different element names.
I currently have them different classes with no base class, however using the same base class would make it easier to implement and more extensible so I am at a bit of a loss of how to achieve the overriding element names of the variables I defined of the base class.
In this case I would say the “base class requirement” is causing you more pain than the value it is delivering.
If you are only using the base class to save some code, ie you don’t want to have extra properties in sub classes? If so just give in and remove the base class. At the cost of having a few extra lines in each sub class you will have less pain moving forward.
If you require the base class for programmatic reasons? For example operations are performed on the base class specifically (polymorphism). Use an interface instead of a base class.
Either way remove the base class.