tags:

views:

58

answers:

1

Suppose you have:

 public enum Priority : short
        {

            Low = 100
            Normal = 200,
            High = 300
        }

I'd like to call WCF service with following call

myWCF.call(Priority.Low);
myWCF.call(Priority.High);
myWCF.call(105);

Is that possible to do without rewriting half of WCF stack? I'd prefer as solution where all WCF config settings would be done to enum type.

Thanks.

+1  A: 

Yes, sure - you could add a second property to your data contract which reflects the int-value of the enum:

[DataContract]
public class YourData
{
   [DataMember]
   public Priority MyPriority { get; set; }

   [DataMember]
   public int MyPriorityAsInt 
   {  
      get { return (int)MyPriority; }
      set { ; }
   }
}

I would think this should work - and MyPriorityAsInt should always accurately reflect the value stored in MyPriority. If you want to, you could even create the setter method for MyPriorityAsInt to set the value of MyPriority as needed.

marc_s