2010-04-15 131 views
1

我有一個枚舉和成員鍵入它C#標誌枚舉分隔符

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

時,序列化該類結果屬性將是這樣的:

<filter search_filter="types attributes methods" /> 

但需要屬性:

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

類的序列化時如何更改分隔符?

回答

2

你將不得不採取的完全控制權,然後 - 比如我標誌着成員作爲[XmlIgnore]並增加了公共財產string如:

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