C#解决XML反序列化空格值被忽略的问题
解决办法:将XmlReaderSettings的值CheckCharacters = false
如下:
using (StreamReader sr = new StreamReader(xmlfilePath)) { var setting = new XmlReaderSettings { CheckCharacters = false }; using (XmlReader r = XmlReader.Create(sr, setting)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); return (T)serializer.Deserialize(r); } }