#region 序列化XML文件 |
/// <summary> |
/// 序列化XML文件 |
/// </summary> |
/// <param name="type">类型</param> |
/// <param name="obj">对象</param> |
/// <returns></returns> |
public static string Serializer(Type type, object obj) |
{ |
MemoryStream Stream = new MemoryStream(); |
//创建序列化对象 |
XmlSerializer xml = new XmlSerializer(type); |
try |
{ |
//序列化对象 |
xml.Serialize(Stream, obj); |
} |
catch (InvalidOperationException) |
{ |
throw ; |
} |
Stream.Position = 0; |
StreamReader sr = new StreamReader(Stream); |
string str = sr.ReadToEnd(); |
return str; |
} |
#endregion |
by: 发表于:2018-01-08 10:17:22 顶(0) | 踩(0) 回复
??
回复评论