Friday, June 24, 2011

Convert object to byte array and vice versa


Convert an object to byte array

private byte[] ObjectToByteArray(Object obj)
{
    if(obj == null)
        return null;
    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();
}
Convert a byte array to object
private Object ByteArrayToObject(byte[] arrBytes)
{
    MemoryStream memStream = new MemoryStream();
    BinaryFormatter binForm = new BinaryFormatter();
    memStream.Write(arrBytes, 0, arrBytes.Length);
    memStream.Seek(0, SeekOrigin.Begin);
    Object obj = (Object) binForm.Deserialize(memStream);
    return obj;
}

Tuesday, June 7, 2011

New article on CodeProject.com: SQL Server Database Comparison Tool

Before a couple of days I have posted new article on CodeProject.com.
This new article is about comparison of databases and how to perform comparison of two databases using Server Management Objects in C#.
More information you can find here.