How to expose enum attributes to WCF client

前端 未结 4 1536
灰色年华
灰色年华 2021-01-12 13:25

I want to expose enum attributes to WCF client application, but I can only see enum values.

Here is the enum:

public enum TemplateType
{
    [EnumDes         


        
4条回答
  •  广开言路
    2021-01-12 13:57

    There is a workaround if the intention is to expose a display text for enum members, define your enum in this way in the contracts:

    public enum EPaymentCycle
    {
        [EnumMember(Value = "Month by Month")]
        Monthly,
    
        [EnumMember(Value = "Week by Week")]
        Weekly,
    
        [EnumMember(Value = "Hour by Hour")]
        Hours
    }
    

    The SvcUtils serialization produces an interesting result:

    public enum EPaymentCycle : int
    {
    
        [System.Runtime.Serialization.EnumMemberAttribute(Value="Month by Month")]
        MonthByMonth= 0,
    
        [System.Runtime.Serialization.EnumMemberAttribute(Value="Week by Week")]
        WeekbyWeek= 1,
    
        [System.Runtime.Serialization.EnumMemberAttribute(Value="Hour by Hour")]
        HourbyHour = 2
    }
    

    You can read the EnumMemberAttribute Value by reflection and there you got it. Also the xsd metadata file produced by svcutil serialization is as expected:

    
    
      
      
      
    
    

提交回复
热议问题