{"id":97,"date":"2006-02-24T19:45:10","date_gmt":"2006-02-25T02:45:10","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/97"},"modified":"2006-02-24T19:45:10","modified_gmt":"2006-02-25T02:45:10","slug":"enummember-and-datacontract","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=97","title":{"rendered":"EnumMember and DataContract"},"content":{"rendered":"<p>In the <a href=\"http:\/\/kennyw.com\/indigo\/96\">February CTP<\/a>, we have a new attribute for interacting with <code class=\"keyword\">enum<\/code> declarations for a <code>[<\/code><code class=\"classname\">DataContract<\/code><code>]<\/code>.  While enums are serializable by default (and thus don&#8217;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:<\/p>\n<div class=\"code\">\n[<code class=\"classname\">DataContract<\/code>(Name=&#8221;ColorContract&#8221;)]<br \/>\nenum Color<br \/>\n{<\/p>\n<div class=\"indent1\">[<code class=\"classname\">EnumMember<\/code>(Value=&#8221;RedValue&#8221;)]<br \/>\n    Red,<\/p>\n<p>    [<code class=\"classname\">EnumMember<\/code>(Value = &#8220;BlueValue&#8221;)]<br \/>\n    Blue,<\/div>\n<p>}\n<\/p><\/div>\n<p>NOTE: <code>[<\/code><code class=\"classname\">EnumMember<\/code><code>]<\/code> is <strong>not<\/strong> used in the case where you have a member variable\/Property of an <code class=\"keyword\">enum<\/code> type in your <code>[<\/code><code class=\"classname\">DataContract<\/code><code>]<\/code>. For those cases, you still use <code>[<\/code><code class=\"classname\">DataMember<\/code><code>]<\/code>, just like you do for the rest of the member variables\/properties that you want to include in the <code>[<\/code><code class=\"classname\">DataContract<\/code><code>]<\/code> for your class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}