Ejemplo n.º 1
0
        public static void ToBinaryBytes(this object @object, int bufferSize, ToBytesCallback callback)
        {
            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, @object);
                ms.Position = 0;

                int read  = 0;
                var bData = new byte[bufferSize];
                do
                {
                    read = ms.Read(bData, 0, bData.Length);

                    if (callback == null)
                    {
                        continue;
                    }

                    callback(bData);
                } while (read > 0);
            }
        }
Ejemplo n.º 2
0
 public static void ToBinaryBytes(this object @object, ToBytesCallback callback)
 {
     ToBinaryBytes(@object, 1024, callback);
 }