This project has moved and is read-only. For the latest updates, please go here.

custom serialization

Mar 25, 2011 at 3:53 PM

I would like to be able to save my db objects asynchronously, but I can't because one of my properties is a SolidColorBrush. It would probably work, however, if I used a custom serializer. What would a custom serializer for a SolidColorBrush look like? Some example code would be greatly appreciated. Thanks.

Mar 27, 2011 at 6:23 PM

It would look something like this - details to hook it up are here:

public class SolidBrushSerializer : BaseSerializer  
    public override bool CanSerialize(Type targetType)
        return targetType.Equals(typeof (SolidColorBrush));                

    public override void Serialize(object target, BinaryWriter writer)
        var data = (SolidColorBrush)target;

    public override object Deserialize(Type type, BinaryReader reader)
        return new SolidColorBrush(Color.FromArgb(
            reader.ReadByte(), reader.ReadByte(),
            reader.ReadByte(), reader.ReadByte());