/// <summary> /// Restores an object from a byte array memento /// </summary> /// <param name="self"></param> /// <param name="byteArray"></param> public static void ReadFrom(this ICanRead self, byte[] byteArray) { var stream = new MemoryStream(); var memento = new StreamMemento(stream, new FormatterStrategy()); stream.Write(byteArray, 0, byteArray.Length); stream.Position = 0; self.ReadFrom(memento); }
private static void ReadFrom(this ICanRead self, IUnformattedReader reader) { if (reader != null) { reader.Read((version) => { self.ReadFrom(reader, version); }); } }
public void WriteTo(ICanRead other) { other.ReadFrom(this); }
/// <summary> /// Initialize an object from a stream /// </summary> /// <param name="self"></param> /// <param name="stream"></param> public static void ReadFrom(this ICanRead self, Stream stream) { var memento = new StreamMemento(stream, new FormatterStrategy()); self.ReadFrom(memento); }
/// <summary> /// Deep-clone one object into another /// </summary> /// <param name="self"></param> /// <param name="other"></param> public static void CloneTo(this ICanRead self, ICanRead other) { other.ReadFrom(new ContiniousReader(self, new FormatterStrategy())); }