gpt4 book ai didi

c# - C# 中的 XML 序列化

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

我有一个如下所示的类:

class SomeClass
{
private int _property1;
[XmlAttribute("Property1")]
public int Property1
{
get { return _property1; }
set { _property1 = value; }
}
private int _property2;
[XmlAttribute("Property2")]
public int Property2
{
get { return _property2; }
set { _property2 = value; }
}

private string _property3;
public string Property3
{
get { return _property3; }
set { _property3 = value; }
}

public SomeClass()
{
}
}

我需要使用以下格式的 XmlSerializer 对其进行序列化:

<SomeClass Property1="NNNNN" Property2="NNNNN">
Value_of_Property3
</SomeClass>

但是,我不知道如何在不为 Property3 添加节点的情况下序列化 Property3 的值。有没有在不添加节点的情况下序列化Property3中的字符串?

最佳答案

[XmlText()] 属性添加到 Property3

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

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