开发者

C# Flag Enum delimiter

开发者 https://www.devze.com 2022-12-27 05:00 出处:网络
I have an Enum and member it type [Flags] public enum SearchFilter { types = 0x01, attributes = 0x02, methods = 0x04

I have an Enum and member it type

 [Flags]
 public enum SearchFilter
 {
    types = 0x01,
    attributes = 0x02,
    methods = 0x04
 }
 [System.Xml.Serialization.XmlAttribute("search-filter")]
 public开发者_StackOverflow中文版 SearchFilter search_filter = SearchFilter.types | SearchFilter.attributes | SearchFilter.methods;

when serialize this class result attribute will be like that:

<filter search_filter="types attributes methods" />

but need attribute:

<filter search_filter="types|attributes|methods" />

how can change delimiter when class serializing?


You're going to have to take complete control of it, then - for example my marking that member as [XmlIgnore] and adding a public string property such as:

[XmlAttribute("search-filter")]
public string SearchShim {
    get { /* translate */ }
    set { /* translate */ }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号