Using Umbrella, it is possible to easily serialize and deserialize objects using the BinaryFormatter and XmlSerializer.

For instance, during the creation of unit tests, it can be important to test if objects can be serialized and deserialized, and still be identical :

    Rectangle r = new Rectangle() { X = 1, Y= 2, Width = 42, Height = 42 };
    Assert.IsTrue(r.Serialization().Binary() == r);
    Assert.IsTrue(r.Serialization().Xml() == r);

An extension also helps the serialization of an instance in a stream and the deserialization of a byte array :

    Rectangle r = new Rectangle() { X = 1, Y = 2, Width = 42, Height = 42 };

    using (var s = new MemoryStream())
    {
        r.Serialization().Binary(s);

        var r2 = r.Serialization().Binary(s.ToArray());

        Assert.IsTrue(r == r2);
    }

Last edited Feb 24, 2009 at 3:30 AM by jlaban, version 1

Comments

No comments yet.