如何将枚举属性公开给WCF客户端 [英] How to expose enum attributes to WCF client
问题描述
这是枚举:
public enum TemplateType
{
[EnumDescription(Property Detailss)]
[EnumValue(PropertyParticulars)]
PropertyParticulars = 1,
[EnumDescription(Short Format Lists)]
[EnumValue(ShortFormatLists)]
ShortFormatLists,
[EnumDescription(Client Letters)]
[EnumValue(ClientLetters)]
ClientLetters,
[EnumDescription(Labels)]
[EnumValue (Labels)]
标签
}
描述和值属性?
您可以从服务中公开枚举,但枚举中的属性在发送时不会被序列化通过电线。这意味着这个枚举的消费者只会看到枚举本身,也不会看到你的属性。
你需要做的是用$ $ c $打包你的枚举c> DataContract 属性以及 EnumMember
属性,以便您的信息将被序列化,但这只允许您指定每个的底层值枚举值,而不是描述。
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.
这篇关于如何将枚举属性公开给WCF客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!