<分区>
Possible Duplicate:
C# WCF: When is it appropriate to use the KnownType attribute?
不久前,我们需要在类里面创建一个 C# 网络客户端作为项目的一部分。老师指导我们把属性DataContract
放在每个要传的类上面。
然后老师告诉我们,如果你有这样的事情:
A / \ / \ B C
you need to write class A in the following way:
[DataContract]
[KnownType(typeof(B))]
[KnownType(typeof(C))]
public class A
{
}
这不是完全违背了多态的思想吗?为什么一个类应该知道谁继承了这个类?