I want to force the NetDataContractSerializer to write property values in a specific order, because the serializer writes them in an alphabetic order.
I know I can achieve this by adding [DataMember(Order = X)] attributes to these properties but this works only when I add [DataContract] attribute to the class I am serializing.
Unfortunately, I can't add the [DataContract] attribute to this class since its base class doesn't have one.
Is there another way to force the order?
I've came up with the idea of using own
ISerializationSurrogatewhere I can handle getting the properties that are being serialized myself.Then I assign the serialization surrogate to the serializer.
And everything works like hell.
NOTE that
Tis the type of the object being serialized/deserialized.