Suppress Base Class XML Serialization

Julio Bello 221 Reputation points
2022-08-06T11:36:54.877+00:00

Hi, Everybody!...

I have a base class and a derived class. I wish to only serialize the derived class. How do I suppress the base class from being serialized when I serialize the derived class?

Thank-you for taking the time to read this.

Developer technologies | .NET | .NET Runtime
Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wellington Faustino 1 Reputation point
    2022-08-07T15:50:06.273+00:00

    You will have to override the serialization method in the extended class, and in this method implement the logic you want. As for the fields, maybe you could create a new instance of the child and assign only the desired fields/values and ignore the base class.

    I hope I've helped


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.