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.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,342 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
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