I have a C# class like this which I want to serialize to XML using XmlSerializer
:
[Serializable] public class MyClass { public string Dat = "DatVal"; //DatVal is not an actual value public string Sol = "SolVal"; public string Opt = "OptVal"; public string Eqp = "EqpVal"; public string Ledev = "LedevVal"; public string Uldev = "Uldev"; public string Flt = "FltVal"; public string TmptCfg = "TmptCfgVal"; //Some other stuffs below, not string }
Now, the Xml serialization works fine with the class above. However, as the 8 items of the class above are actually of the same type string
. And currently I use them like this
string name = myClass.Dat; //then I will get DatVal
While they actually refer to the same type of item, which is table name (I have set of tables functioned as "Dat", "Sol", "Opt", "Eqp"
, etc whose actual names come from other developers - thus come "DatVal", "SolVal", "OptVal", "EqpVal"
, etc..)
Thus, I am thinking of serializing them using List of KVP such that when I need to call any of them, I would simply need to do this
string name = myClass.MyList["Dat"]; //then I will get "DatVal"
Then, as I learn more, I understand that KVP cannot be meaningfully serialized.
My question is, how do we normally serialize such case if not using KVP
? Is there any built-in way available to serialize such case?
No comments:
Post a Comment