序列化反序列化 Common Utilities 功能
此示例用于所有类型对象序列化和反序列化的常用功能。
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
namespace Framework
{
public static class IGUtilities
{
public static string Serialization(this T obj)
{
string data = JsonConvert.SerializeObject(obj);
return data;
}
public static T Deserialization(this string JsonData)
{
T copy = JsonConvert.DeserializeObject(JsonData);
return copy;
}
public static T Clone(this T obj)
{
string data = JsonConvert.SerializeObject(obj);
T copy = JsonConvert.DeserializeObject(data);
return copy;
}
}
}