我想为 xml 序列化创建通用函数,但是有一个问题需要对要序列化的对象进行 typeof,但我不知道它可以是什么类型的对象(persondetails 或 logindetails)我引用了这个示例并尝试修改但typeof 用红色下划线请帮帮我
原来的
static public void SerializeToXML(Movie movie)
{
XmlSerializer serializer = new XmlSerializer(typeof(Movie));
TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
serializer.Serialize(textWriter, movie);
textWriter.Close();
}
我的代码
public class XmlSerialization
{
static public string SerializeToXML("What type have to put here")
{
string xmlReturn="";
XmlSerializer serializer = new XmlSerializer(typeof("What type have to put here"));
TextWriter textWriter = new StreamWriter(xmlReturn);
serializer.Serialize(textWriter, xml);
textWriter.Close();
return xmlReturn;
}
}