DataContractSerializer 按不使用 IgnoreDataMemberAttribute 的条件忽略属性

发布于 2024-12-20 23:58:17 字数 82 浏览 3 评论 0原文

有没有办法在不使用 IgnoreDataMemberAttribute 的情况下忽略对象的属性?

例如我想忽略所有以 Id 结尾的属性

Is there any way to ignore a property on an object without using IgnoreDataMemberAttribute?

For example I want to ignore all properties which end with Id

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-12-27 23:58:17

使用 IDataContractSurrogate 可以让您在每个类型或每个对象的基础上进行自定义序列化和反序列化。在您的情况下,您将有两种类型 A 和 B。A 将是原始类型,B 将是没有您不关心的幻影成员的 A。

代理已经存在了一段时间,甚至在 WCF 之前,它们的想法很简单:将 A 等对象图的一部分替换为 B 的一部分(“代理”)。

The use of IDataContractSurrogate lets you do custom serialization and deserialization on a per-type or per-object basis. In your case, you'd have two types A and B. A would be the original type, and B would be A without the phantom member you don't care about.

Surrogates have been around for a while, even before WCF, and their idea is simple: replacing something that is part of an object graph like A to to be serialized as part of B (the “surrogate”).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文