c# - 如何使用用于 XML 序列化的公共(public)访问器指定非序列化字段

标签 c# serialization .net-3.5 xml-serialization nonserializedattribute

如何为 XML 序列化指定带有公共(public)访问器的非序列化字段?

[NonSerialized]
public String _fooBar;
//Declaring the property here will serialize the _fooBar field
public String FooBar
{
    get { return _fooBar; }
    set { _fooBar = value; }
}

最佳答案

BinaryFormatter 不会序列化属性,只有字段。 [NonSerialized] 属性对 XML 序列化没有意义。请改用 [XmlIgnore]

关于c# - 如何使用用于 XML 序列化的公共(public)访问器指定非序列化字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5560532/

相关文章:

c# - 在登录表单页面上加载 javascript/css?

c# - 无法序列化 session 状态... [已更新!]

c# - 如何在 ActiveDirectory 和 .NET 3.5 中确定用户所属的所有组(包括嵌套组)

c# - 如何在 C# 中仅从 DateTime 序列化 Xml Date

java - 让 Jackson XMLMapper 在代码中设置根元素名称

c# - 数组的通用扩展方法无法编译

c# - .NET 3.5 中的 HashSet<T> 有什么特别之处?

c# - 如何在 Windows 中以编程方式获取电源使用情况

c# - 如何读取ANSI编码非英文字母的文本文件?

c# - SL 从 ListItem 数据模板中向 MainPage.xaml 的 ViewModel 触发命令