/// <summary>
/// 序列化
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
[DebuggerStepThrough]
public static string Serialize(this string target)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter br = new BinaryFormatter();
br.Serialize(ms, target);
byte[] resultbyte = ms.ToArray();
string resultstr = Convert.ToBase64String(resultbyte, 0, resultbyte.Length);
return resultstr.Replace("+", "%2B");
}
/// <summary>
/// 反序列化
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
[DebuggerStepThrough]
public static string Deserialize(this string target)
{
var str = target.Replace("%2B", "+");
byte[] bb = Convert.FromBase64String(str);
MemoryStream ms = new MemoryStream(bb);
BinaryFormatter br = new BinaryFormatter();
object o = br.Deserialize(ms);
ms.Flush();
return o.ToString();
}