How to prevent auto implemented properties from being serialized?

后端 未结 7 1513
终归单人心
终归单人心 2020-12-10 10:28

How can I prevent a auto implemented property from being serialized by the binary formatter? The [NonSerialized] attribute can only be used with fields. And the field is hi

7条回答
  •  借酒劲吻你
    2020-12-10 10:45

    It's not possible for auto implemented properties. Consider folowing:

    This behavior is "by design". The decision at the time auto-properties were implemented was that they would work in the "common case" which among other things means no attributes on the generated field. The idea behind that is keeping them simple and not slowly mutating them into full properties. So, if you need to use the NonSerialized attribute full properties are the way.

    (http://social.msdn.microsoft.com/Forums/en-US/vcsharp2008prerelease/thread/2b6eb489-122a-4418-8759-10808252b195)

提交回复
热议问题