XmlSerializer property converter

前端 未结 3 764
离开以前
离开以前 2020-12-03 17:57

Suppose we have a class which can be serialized/deserialized by XmlSerializer. It would be like so:

[XmlRoot(\"ObjectSummary\")]
public class Summary
{
              


        
3条回答
  •  攒了一身酷
    2020-12-03 18:22

    The way I do it - which is suboptimal but have not found a better way - is to define two properties:

    [XmlRoot("ObjectSummary")]
    public class Summary
    {
         public string Name {get;set;}
         [XmlIgnore]
         public bool IsValid {get;set;}
         [XmlElement("IsValid")]
         public string IsValidXml {get{ ...};set{...};}
    
    }
    

    Replace ... with the simple code to read and write the IsValid value to Y and N and read from it.

提交回复
热议问题