我有DataContract
定义的 WCF 和其他DataContract
一些扩展它的 WCF。所以它的原始形式看起来像这样:
[DataContract(Name = "FacilityPerson"]
[KnownType(typeof(Student))]
[KnownType(typeof(Teacher))]
public class Person
{
[DataMember(IsRequired=true)]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public DateTime? DOB { get; set; }
}
[DataContract]
public class Student
{
[DataMember(IsRequired=true)]
public int StudentID { get; set; }
}
[DataContract]
public class Teacher
{
[DataMember(IsRequired=true)]
public int StaffID { get; set; }
}
我有一个ServieContract
只有一个操作,看起来像这样:
[OperationContract(Name = "ReportNewPerson")]
void ReportNewTeacherOrStudent(Person person);
我的问题是当我实现它时,我无法访问父对象的子属性。
public class UniversityService : IUniversityServiceContract
{
void ReportNewTeacherOrStudent(Person person)
{
if(person.GetType().FullName == "Student")
{
//here I have a parent object so I cannot getStudentId which is a child property
Console.Writeline(person.StudentId);
}
}
}
我应该在这里做什么?