gpt4 book ai didi

c# - xml序列化c#

转载 作者:数据小太阳 更新时间:2023-10-29 02:00:38 25 4
gpt4 key购买 nike

无法理解我做错了什么,结果集是空的。
我的代码:

class Class1
{

public static object DeSerialize()
{
object resultObject;

XmlSerializer serializer = new XmlSerializer(typeof(PointsContainer));
using (TextReader textReader = new StreamReader(@"d:\point.xml"))
{
resultObject = serializer.Deserialize(textReader);
}

return resultObject;


}
}

[Serializable]
[XmlRoot("Points")]
public class PointsContainer
{
[XmlElement("Point")]
private List<Point> items = new List<Point>();

public List<Point> Items
{
get { return items; }
set { items = value; }
}


}


[Serializable]
public class Point
{
[XmlAttribute]
public bool x { get; set; }

[XmlAttribute]
public bool y { get; set; }
}

XML:

<Points>  
<Point x="1" y="5"/>
<Point x="21" y="3"/>
<Point x="3" y="7"/>
</Points>

最佳答案

[XmlElement] 属性移动到属性。
XmlSerializer 忽略私有(private)成员。

关于c# - xml序列化c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4146804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com