Ignore inherited class when serializing object

后端 未结 4 1435
不思量自难忘°
不思量自难忘° 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 22:18

    If B inherits from A, it inherits PropertyA, and there's nothing you can do about it. If you don't want to serialize PropertyA when serializing an instance of B, perhaps you shouldn't be inheriting A in the first place...

    Anyway, I don't think XML serialization can help you with what you're trying to do, unless you implement IXmlSerializable yourself...

提交回复
热议问题