嗨,我的数据合同具有继承性,但在使用服务时无法访问最后一个成员:
namespace Services.SearchService
{
[DataContract]
[KnownType(typeof(LabellingSearch))]
public class SearchResult
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public DateTime Modified { get; set; }
}
/// <summary>
/// Specialist Search Result for Labelling Content Data
/// </summary>
[DataContract]
[KnownType(typeof(Labelling))]
public class LabellingSearch : SearchResult
{
[DataMember]
public string Region { get; set; }
[DataMember]
public string Country { get; set; }
[DataMember]
public string LabelSummary { get; set; }
}
/// <summary>
/// Full Labelling Content Data
/// </summary>
[DataContract]
public class Labelling : LabellingSearch
{
public string Content { get; set; }
}
}
因此,在消费类中,我可以访问“标签”类型,但无法访问其“内容”属性。