public void WriteTo(ICanRead other) { other.ReadFrom(this); }
/// <summary> /// Save an object to a stream /// </summary> /// <param name="self"></param> /// <param name="stream"></param> public static void WriteTo(this ICanRead self, Stream stream) { IMemento memento = new StreamMemento(stream, new FormatterStrategy()); memento.ReadFrom(self); }
/// <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); }
public ContiniousReader(ICanRead readable, IFormatterStrategy readFormatter) { ReadFormatter = readFormatter; Readers = new Stack <IEnumerator>(); Readers.Push(readFormatter.ReadFormatted(readable).GetEnumerator()); }
/// <summary> /// Returns a snapshot memento of an object /// </summary> /// <param name="self"></param> /// <returns></returns> public static IMemento GetMemento(this ICanRead self) { return(self.GetMemento(new MemoryStream())); }
/// <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())); }
public ReadWriter(IReaderWriterFactory factory) { reader = factory.CreateReader(); writer = factory.CreateWriter(); }