Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 private static void ReadFrom(this ICanRead self, IUnformattedReader reader)
 {
     if (reader != null)
     {
         reader.Read((version) =>
         {
             self.ReadFrom(reader, version);
         });
     }
 }
Exemplo n.º 3
0
 public void WriteTo(ICanRead other)
 {
     other.ReadFrom(this);
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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()));
 }