I want to expose enum attributes to WCF client application, but I can only see enum values.
Here is the enum:
public enum TemplateType
{
[EnumDescription("Property Particulars")]
[EnumValue("PropertyParticulars")]
PropertyParticulars = 1,
[EnumDescription("Short Format Lists")]
[EnumValue("ShortFormatLists")]
ShortFormatLists,
[EnumDescription("Client Letters")]
[EnumValue("ClientLetters")]
ClientLetters,
[EnumDescription("Labels")]
[EnumValue("Labels")]
Labels
}
How can I expose the Description and Value attributes?
You can expose enums from a service but the attributes on an enum are not serialized when they are sent over the wire. This means that consumers of this enum will only see the enum itself and none of your attributes.
What you need to do is dress up your enum with a DataContract
attribute and the values with the EnumMember
attribute so that your information will be serialized, but this will only allow you to specify the underlying value of each enum value, not a description.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With