I have this C# dictionary
var dic = new Dictionary<string, Type>() {
{ "A1", typeof(Model.ABC) },
{ "A2", typeof(Model.XYZ) }
};
How do I get the class Model.XYZ
? When I use dic["A2"]
, I can only get typeof(Model.XYZ)
, but I need just Model.XYZ
The reason of the above is I can use dictionary to pass the typeof
during XmlSeriliazer constructor and the class name at Deserialize
method. Below is the code is now hardcoded to use Model.XYZ
which I needed to get is from dictionary.
var serializer = new XmlSerializer(dic["A2"]);
using (TextReader reader = new StreamReader(new FileStream(filePath, FileMode.Open)))
{
var obj = (Model.XYZ)serializer.Deserialize(reader);
}