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)?
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.
加载中,请稍侯......
精彩评论