Beispiel #1
0
        public static MemoryStream SaveDataIntoMemoryStream <DataType>(DataType input)
        {
            var data   = new MemoryStream();
            var writer = new BinaryWriter(data);

            BinaryDataSaver.SaveDataType(input, typeof(DataType), writer);
            return(data);
        }
Beispiel #2
0
 /// <summary>
 /// Saves any object type information and the actual data contained in in, use Create to load.
 /// </summary>
 public static void Save(object data, BinaryWriter writer)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     writer.Write(GetShortName(data));
     WriteDataVersionNumber(data, writer);
     BinaryDataSaver.SaveDataType(data, data.GetType(), writer);
 }
Beispiel #3
0
 public static byte[] ToByteArray(object data)
 {
     using (var messageStream = new MemoryStream())
         using (var messageWriter = new BinaryWriter(messageStream))
         {
             if (data is IList)
             {
                 foreach (object value in data as IList)
                 {
                     BinaryDataSaver.SaveDataType(value, value.GetType(), messageWriter);
                 }
             }
             else
             {
                 BinaryDataSaver.SaveDataType(data, data.GetType(), messageWriter);
             }
             return(messageStream.ToArray());
         }
 }