Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
序列化此类工作正常。但是,有时我想排除该字段。这可能吗?
[DataContract] class Foo { [DataMember] Foo _Foo; }
暂时将字段设置为 null 是不可能的。
如果有人偶然发现同样的问题,我将展示我所采用的解决方案。
这个想法是像这样对原始字段进行外观:
[DataContract] class Foo { Foo _FooOriginal; [DataMember] Foo _Foo { get { return whatever ? _FooOriginal : null; } set { _FooOriginal = value; } } }