Ignore inherited class when serializing object

后端 未结 4 1437
不思量自难忘°
不思量自难忘° 2021-01-24 21:29

When I inherit from a class and serialize the new class I get all all properties. How can I prevent that? I have no control over the class that I inherit from. So I can\'t add

4条回答
  •  太阳男子
    2021-01-24 21:56

    One solution is to use the [Nonserialized] attribute on PropertyA. Note that with this attribute, PropertyA will never be serialized, including when you serialize an instance of class A. Is that acceptable?

提交回复
热议问题