I have a class that I want to have opportunities to serialize/deserialize.
It implements interface IXMLConvertable:
public interface IXMLConvertable<T>
where T: new() {
T deserialize(XElement element);
void serialize(XElement element);
}
when T is a type of object to deserialize. The question is whether it`s a good practice or not to specify XML tag names not in code, but in string constants, like this:
public class XMLTagger {
Dictionary<String, String> xmltags; /*key is fieldname to serialize, value is the tag for it*/
//...
public void addNewTag(String field, String tagForIt) {
xmltags.Add(field, tagForIt);
}
//...
}
I hope you get the idea. This class can be used by every my class which objects I want to serialize/deserialize and provides easy way to get tag you want by the name of the field. Is is a good idea or not?