gpt4 book ai didi

c# - 抽象类继承和数据契约

转载 作者:太空宇宙 更新时间:2023-11-03 14:16:50 25 4
gpt4 key购买 nike

我有一个 abstract class BaseClass,它有两个属性,我想与 class ClassA : BaseClassclass ClassB : BaseClass 共享。但是,我希望 ClassAClassB 都用 DataContractAttribute 标记,成员继承自 BaseClass契约(Contract)中也有暴露。但是,我不希望将 BaseClass 本身作为数据协定公开。这在 WCF (.NET 3.5) 中可能吗?

最佳答案

不,据我所知这是不可能的。即使您新建属性来添加数据成员标记,它仍然会报错:

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.

关于c# - 抽象类继承和数据契约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6356870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com