Force XML serialization to serialize readonly property

In C#, I have a class which has a derived property that should be serialized via XML. However, XML serialization (by default) doesn't serialize read=only properties. I can work around this by defining an empty setter like so:

public virtual string IdString
{
    get { return Id.ToString("000000"); }
    set { /* required for xml serialization */ }
}

But is there a cleaner more semantically correct way, short of writing my own ISerializable implementation?

33
задан Chris 7 April 2011 в 17:50
поделиться