我有一个我想概括的方法。我想对任何对象类型使用以下反序列化函数,如下所示:
ExportDefinition _expDefinition = new ExportDefinition("a.ini");
DeliveryDefinition _delDefinition = new DeliveryDefinition("b.ini");
ExportDefinition expDef = Deserialize(_expDefinition);
DeliveryDefinition devDef = Deserialize(_delDefinition);
public SomeType Deserialize(SomeType?? tp) // What should I use instead of SomeType?
{
try
{
FileStream readFileStream = new FileStream(definitionFile, FileMode.Open, FileAccess.Read, FileShare.Read);
XmlSerializer serializerObj = new XmlSerializer(typeof(tp));
tp loadedObj = (tp)serializerObj.Deserialize(readFileStream);
readFileStream.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return loadedObj;
}
任何想法,如何实现这一目标?