📄 serialize.cs
字号:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
namespace serialization
{
/// <summary>
/// Summary description for Serialize.
/// </summary>
public class Serialize
{
public Serialize()
{
//
// TODO: Add constructor logic here
//
}
public string EnSerialize(object Pd)
{
MemoryStream ms = new MemoryStream();
XmlSerializer sr=new XmlSerializer(Pd.GetType());
sr.Serialize(ms,Pd);
ms.Close();
byte [] bt = ms.GetBuffer();
string str=null;
for(int i=0;i<bt.Length;i++)
{
str+=Convert.ToChar(bt[i]);
}
return str;
}
public object DeSerialize(string str)
{
char [] ch = str.ToCharArray();
byte [] bt = new byte[str.Length];
for(int i=0;i<ch.Length;i++)
{
bt[i] = (byte)ch[i];
}
MemoryStream ms = new MemoryStream(bt,0,bt.Length);
XmlSerializer newSr=new XmlSerializer(typeof(System.Type));
object newPd = null;
newPd=(object)newSr.Deserialize(ms);
return newPd;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -