c# - 非序列化属性

标签 c# .net serialization properties

当我写这样的代码时

[XmlIgnore]
[NonSerialized]
public List<string> paramFiles { get; set; }

我收到以下错误:

Attribute 'NonSerialized' is not valid on this declaration type.
It is only valid on 'field' declarations.


如果我写

[field: NonSerialized]

我收到以下警告

'field' is not a valid attribute location for this declaration.
Valid attribute locations for this declaration are 'property'.
All attributes in this block will be ignored.


如果我写

[property: NonSerialized]

我(再次)收到以下错误:

Attribute 'NonSerialized' is not valid on this declaration type.
It is only valid on 'field' declarations.


如何在属性上使用 [NonSerialized]

最佳答案

简单使用:

[XmlIgnore]
[ScriptIgnore]
public List<string> paramFiles { get; set; }

希望对您有所帮助。

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

相关文章:

c# - 正确重写 Newtonsoft.Json 方法

c# - Entity Framework 4 获取插入记录的主键 ID

java - 在snakeyaml中转储时创建Ruby优化版本

c# - 使用 Entity Framework 从 Excel 工作表中读取数据

c# - 使用 HTML 的 Windows 窗体应用程序

c# - 结构体中的自引用通用成员

.net - 属性与评论

c# - 如何确定一个值是否与另一个值几乎相同(例如街道缩写)?

jquery - 如何使用 JQuery AJAX 在 GET 请求中将数组作为查询字符串传递

serialization - Kotlin 序列化 : "Unresolved reference: serializer"