This is a mirror of official site: http://jasper-net.blogspot.com/

Enumeration in DataContract of WCF

| Sunday, April 10, 2011
By default Enums are serializable. If we define Enum at service side and use it in Data Contract, it is exposed at the client side.

For example, if we have an Enum as below,

public  enum ProductDeliveryPriority
{
    Low,
    Normal,
    High,
    Urgent
}

And we are using it in DataContract as below

[DataMember]
public  ProductDeliveryPriority ProductPriority;

By default Enum is serialized.

So, let us see the default behavior of Enum with an example.

Create a DataContract called Product.

Product.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace WcfService1
{
    [DataContract]
    public class Product
    {
        [DataMember]
       public  string ProductName;
        [DataMember]
       public  ProductDeliveryPriority ProductPriority;
    }
   public  enum ProductDeliveryPriority
    {
        Low,
        Normal,
        High,
        Urgent
    }
}

Posted via email from Jasper-net

0 comments: