B.M
B.M

Reputation: 563

Abstract Class Inheritance & Data Contracts

I have an abstract class BaseClass with two attributes I want to share with class ClassA : BaseClass and class ClassB : BaseClass. However, I want both ClassA and ClassB to be marked with DataContractAttribute in a way that the members inherited from BaseClass are also exposed in the contract. However, I don't want BaseClass itself to be exposed as a data contract. Is this possible in WCF (.NET 3.5)?

Upvotes: 2

Views: 1141

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062945

No, AFAIK that is not possible. Even if you new the properties to add data-member markers it'll still complain:

Type 'BaseClass' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

Upvotes: 1

Related Questions