Serialize char data type with XmlSerializer

c#, xml-serialization

Solution

Not AFAIK. You can cheat, though:

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

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

Problem

I have a class which has property whiches type is char as following ``` [XmlRoot("Root")] public class TestClass { [XmlElement("Test", typeof(char))] public char TestProperty { get; set; } } ``` When value of TestProperty is 'N' and if I serialize TestClass it will produce following result: ``` <Root> <Test>78</Test> </Root> ``` But what I want is to have following ``` <Root> <Test>N</Test> </Root> ``` Is it possible without changing type of TestProperty to string?

Original source