[英]How to Serialize in json new properties after hide it in derived class
I have to parent class such as: 我必须上课,如:
public class Title
{
public List<Detail> details {get; set;}
}
public class Detail
{
// some properties
}
public class TitleChild : Title
{
public new List<DetailChild> details {get; set;} // hiding
}
public class DetailChild : Detail
{
// some properties
}
I need to serialize a list of Title List<Title>
and list of TitleChild List<TitleChild>
我需要序列化Title
List<Title>
列表和TitleChild List<TitleChild>
Everythings is ok in List<Title>
but in List<TitleClild>
some things are wrong. 在
List<Title>
一切正常,但在List<TitleClild>
有些事情是错误的。 After deserializing it in javascript I notice that the details properties steel is the hidden property in the superclass. 在javascript中反序列化之后,我注意到details属性steel是超类中的隐藏属性。
What should I do ? 我该怎么办 ?
And also I can't ignore serializing on hidden property is superclass because I need it in serializing time on the superclass. 而且我也不能忽略对隐藏属性的超类序列化,因为在超类的序列化时间中需要它。
Serialization most likely just traverses public properties. 序列化很可能只是遍历公共属性。 You have hidden your details on purpose with the
new
keyword. 您已经使用
new
关键字故意隐藏了详细信息。 You can try changing the structure so that you do not use new
. 您可以尝试更改结构,以免使用
new
。 It seems rather weird in here really and you'd better avoid it in any case. 在这里看起来确实很奇怪,无论如何都最好避免这样做。
Eg if you want both properties back, you can change the name of details
to childrenDetails
and remove new
. 例如,如果您希望同时返回两个属性,则可以将
details
的名称更改为childrenDetails
并删除new
。
PS Since your DetailChild
inherits from Detail
, you can really just use the original details
list and populate it with DetailChild
objects. PS由于您的
DetailChild
继承自Detail
,因此您实际上可以只使用原始的details
列表并用DetailChild
对象填充它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.