C#继承类与父类序列化测试

2020-12-18 03:32

阅读:417

标签:ali   number   identify   name   serial   div   end   span   class   

//父类可序列化
    [Serializable]
    [DataContract]
    public class QueryParameters
    {
        [DataMember]
        public string ApplicantName { get; set; }
        [DataMember]
        public string IdentifyNumber { get; set; }
    }
//继承类也可序列化
    [Serializable]
    [DataContract]
    public class AntiFraudRequestParamters : QueryParameters
    {
        [DataMember]
        public string QueryEmployee { get; set; }
        [DataMember]
        public string QueryReason { get; set; }
        [DataMember]
        public string QueryEndDate { get; set; }

    }
var bhParas = new AntiFraudRequestParamters ();
            string entity = JsonConvert.SerializeObject(bhParas, Formatting.None);
//NewTonSoft.Json序列化得到结果:
{
    "ApplicantName": null,
    "IdentifyNumber": null,
    "QueryEmployee": null,
    "QueryReason": null,
    "QueryEndDate": null
}
//继承类不加可序列化
    public class AntiFraudRequestParamters : QueryParameters
    {
        public string QueryEmployee { get; set; }
        public string QueryReason { get; set; }
        public string QueryEndDate { get; set; }

    }
            var bhParas = new AntiFraudRequestParamters ();
            string entity = JsonConvert.SerializeObject(bhParas, Formatting.None);
//NewTonSoft.Json序列化得到结果:
{
    "ApplicantName": null,
    "IdentifyNumber": null
}
//结果没有得到继承类加的三个属性

 

C#继承类与父类序列化测试

标签:ali   number   identify   name   serial   div   end   span   class   

原文地址:https://www.cnblogs.com/hofmann/p/13976201.html


评论


亲,登录后才可以留言!