问题
Is it possible to conditionally serialize a property from an object using protobuf-net?
回答1:
protobuf-net supports the standard conditional serializers patterns, so for property Foo
, a method like bool ShouldSerializeFoo()
or a property bool FooSpecified
(with at least a getter) should work fine. These same techniques are supported my multiple serialization and UI frameworks.
Or more simply, for value-type properties, you can just use Nullable<T>
. A null value will not be serialized.
来源:https://stackoverflow.com/questions/35469388/conditional-serialization-with-protobuf-net