public byte[] Serialize() { byte[] result; using (MemoryStream memoryStream = new MemoryStream()) { PolicySyncCookie.GetSerializer().WriteObject(memoryStream, this); result = memoryStream.ToArray(); } return(result); }
public static PolicySyncCookie Deserialize(byte[] bytes) { if (bytes == null) { return(new PolicySyncCookie()); } PolicySyncCookie result; using (MemoryStream memoryStream = new MemoryStream(bytes)) { PolicySyncCookie policySyncCookie = PolicySyncCookie.GetSerializer().ReadObject(memoryStream) as PolicySyncCookie; if (policySyncCookie == null) { throw new InvalidOperationException("Failed to deserialize cookie data"); } result = policySyncCookie; } return(result); }