小知识:typeof(类型名)和实例.GetType()是什么?
typeof(类名):返回直指的System.Type对象,并可以通过Type对象访问基类及本类一些信息
GetType():是object类下实例方法,即无论是自己定义的类还是.net框架类都可以用此方法
如果想返回String类型的全类型形式,可以用typeof(String)
如果想返回对象string a=null;中实例a的类型,可以用a.GetType()
#region XML序列化
public static void XmlSerialize(object type)
{
XmlSerializer xs = new XmlSerializer(type.GetType());
Stream stream = new FileStream("c:\\zzl.XML", FileMode.Create,
FileAccess.Write, FileShare.Read);
xs.Serialize(stream, type);
stream.Close();
}
public static object XmlDeserialize(Type type)
{
XmlSerializer xs = new XmlSerializer(type);
Stream stream = new FileStream("C:\\zzl.XML", FileMode.Open,
FileAccess.Read, FileShare.Read);
object list = xs.Deserialize(stream) as object;
stream.Close();
return list;
}
#endregion