EnumMember and DataContract

In the February CTP, we have a new attribute for interacting with enum declarations for a [DataContract]. While enums are serializable by default (and thus don’t require attribute decoration), you may want to customize the contract names of your enum values (i.e. the names that go on the wire) separately from your implementation naming so that you can version the two independently. For example:

[DataContract(Name=”ColorContract”)]
enum Color
{

[EnumMember(Value=”RedValue”)]
Red,

[EnumMember(Value = “BlueValue”)]
Blue,

}

NOTE: [EnumMember] is not used in the case where you have a member variable/Property of an enum type in your [DataContract]. For those cases, you still use [DataMember], just like you do for the rest of the member variables/properties that you want to include in the [DataContract] for your class.

One thought on “EnumMember and DataContract

  1. Pingback: mattonsoftware.com : .NET Resources

Leave a Reply

Your email address will not be published. Required fields are marked *