2013-04-17 15 views
9

ho una classe che ha proprietà whiches tipo è char come segueSerialize tipo di dati char con XmlSerializer

[XmlRoot("Root")] 
    public class TestClass 
    { 
     [XmlElement("Test", typeof(char))] 
     public char TestProperty { get; set; } 
    } 

Quando il valore di TestProperty è 'N' e se serializzare TestClass esso produrrà seguente risultato:

<Root> 
     <Test>78</Test> 
    </Root> 

Ma quello che voglio è avere seguito

<Root> 
     <Test>N</Test> 
    </Root> 

E 'possibile ingegno hout cambiando il tipo di TestProperty in stringa?

risposta

7

Non AFAIK. Potete imbrogliare, però:

[XmlIgnore] 
public char TestProperty { get; set; } 

[XmlElement("Test"), Browsable(false)] 
public string TestPropertyString { 
    get { return TestProperty.ToString(); } 
    set { TestProperty = value.Single(); } 
} 
+0

Grazie. È bene che ora non proverò a farlo). Quindi è preferibile cambiare il tipo di TestProperty in stringa, credo. –

Problemi correlati