Clone With Serialization : Serialization « File Stream « C# / C Sharp






Clone With Serialization

        

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace AltSerializer.Tests
{
    public static class Common
    {

        public static T CloneWithSerialization<T>(T original) where T : class
        {
            T result;
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(stream, original);
                stream.Seek(0, SeekOrigin.Begin);
                result = (T)binaryFormatter.Deserialize(stream);
            }

            return result;
        }


    }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Use Serializable attribute to mark a generic class
2.Use Serializable attribute to mark a class
3.Deserialize Object
4.Serialize and DeSerialize
5.Three types of Serialization: Binary, Soap, XML
6.Use XML Serialization with Custom ObjectsUse XML Serialization with Custom Objects
7.Working with the Serializable Attribute
8.NonSerialized attributesNonSerialized attributes
9.Serialize hiearchy classesSerialize hiearchy classes
10.C# Serialization C# Serialization
11.Serial Employee class
12.Set XML tag name for Serialization
13.illustrates binary serializationillustrates binary serialization
14.Deserialize
15.Collection Serialization
16.Serializes an object to binary
17.Deserializes an object from binary
18.Object to string serialization/Deserialization
19.Object to byte array serialization/Deserialization
20.Javascript Serializer
21.Serialize and Deserialize (2)
22.Binary Serializer
23.Deserialize the incomming data to the T datatype, this method used to deserialize the test cases data to the required entity
24.Serialization Utility
25.Serialization Utilities