DataContractSerializer 按不使用 IgnoreDataMemberAttribute 的条件忽略属性
有没有办法在不使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 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”).