WCF enum - any way to transfer both valid enum values AND numbers
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.
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.
精彩评论