Using XmlSerializer with private and public const properties

前端 未结 6 2077
渐次进展
渐次进展 2020-12-19 08:07

What\'s the simplest way to get XmlSerializer to also serialize private and \"public const\" properties of a class or struct? Right not all it will output for me is things

6条回答
  •  感动是毒
    2020-12-19 08:54

    One other solution the use of Newtonsoft.Json:

       var json = Newtonsoft.Json.JsonConvert.SerializeObject(new { root = result });
       var xml = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json);
    

    Sure, this one has unfortunately detour via json.

提交回复
热议问题