gpt4 book ai didi

c# - 使用 WCF 的 DataContract/Data 成员序列化对象

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

我正在尝试序列化我的数据层对象。这些是具有属性、方法和对象集合的复杂对象。

所有类都继承自序列化的基类。

    [DataContract]
[KnownType(typeof(Person))]
[KnownType(typeof(Client))]
[KnownType(typeof(Professional))]
[KnownType(typeof(ProfessionalApptHistory))]
[KnownType(typeof(DailySchedule))]
[KnownType(typeof(Option))]
[KnownType(typeof(PersonType))]
[KnownType(typeof(ProfessionClientInteractionType))]
[KnownType(typeof(ProfessionalClientInteractions))]
[KnownType(typeof(ProfessionalCalendar))]
public abstract class CMBase
{
protected designs3_OurTimeEntities _entities = new designs3_OurTimeEntities();
[DataMember()]
public abstract bool IsPersisted { get; internal set; }
}

我有一个也被序列化的 person 类

    [DataContract(Name = "Person")]
[KnownType(typeof(Professional))]
[KnownType(typeof(Client))]
public abstract class Person : CMBase
{
[DataMember()]
public int PersonId { get; internal set; }
[DataMember()]
public int PersonTypeId { get; set; }
[DataMember()]
public string Name { get; set; }
[DataMember()]
public string ContactNumber { get; set; }
[DataMember()]
public string ImageLocation { get; set; }
[DataMember()]
public Bitmap Image { get; internal set; }
[DataMember()]
public Guid MembershipUserId { get; internal set; }
[DataMember()]
public DateTime? ActivationStartDate { get; internal set; }
[DataMember()]
public string Email { get; internal set; }
[DataMember()]
public string Zip { get; set; }
[DataMember()]
public bool ShowDefaultPage { get; set; }
[DataMember()]
public bool IsClient { get; internal set; }

[DataMember()]
public override bool IsPersisted
{
get
{
if (this.PersonId == 0)
{
return false;
}
else
{
return true;
}
}
internal set
{
throw new NotImplementedException();
}
}

...

然后我有这个类,它不会被序列化

    [DataContract(Name = "Professional")]
public class Professional : Person
{
[DataMember()]
public DateTime DateStartedInProfession { get; set; }
[DataMember()]
public int? ShopId { get; set; }
[DataMember()]
public DateTime LastPayment { get; set; }
[DataMember()]
public DateTime NextPaymentDate { get; set; }
[DataMember()]
public DateTime TerminationDate { get; set; }
[DataMember()]
public int? Rating { get; internal set; }
[DataMember()]
public bool hasSystemAccess { get; internal set; }
[DataMember()]
public List<SaveResult> SaveResults { get; internal set; }
...
}

我还有其他未序列化的类,我不明白发生了什么。

最佳答案

看看Serialize a nullable int

它有一些您可以遵循的方法。

关于c# - 使用 WCF 的 DataContract/Data 成员序列化对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872225/

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