当我从 DocumentDB 序列化 JSON 对象时,我的Control
没有反序列化到OptionsControl
与Options
财产。
我有以下课程,Control
:
public class Control : IControl
{
public Guid Id { get; set; }
public virtual Enums.ControlType Type { get; set; }
public string PropertyName { get; set; }
public string ControlCssClass { get; set; }
public string Description { get; set; }
}
我也有OptionsControl
,它继承自Control
:
public class OptionsControl : Control
{
public IDictionary<string, string> Options;
}
我也有一个ClickableControl
:
public class ClickableControl : Control
{
public string Url { get; set; }
public string UrlTarget { get; set; }
}
我使用 Azure 中的文档资源管理器将此 JSON 放入document
在文档数据库中collection
:
Rows:
[
{
Controls:
[
{
"PropertyName": "Relationship",
"ControlCssClass": "",
"Description": "",
"Type": 3,
"Options": [
{
"Key": "Spouse",
"Value": "Spouse"
},
{
"Key": "Child",
"Value": "Child"
},
{
"Key": "Step-child",
"Value": "Step-child"
}
],
}
]
}
]
当我从 DocumentDB 中提取数据时,我尝试将其序列化到我的Row
class:
public class Row
{
public IList<Control> Controls { get; set; }
}
我需要能够将任何类型的“Control”放入 DocDB 的控制列表中,并让 C# 将该列表反序列化回正确的位置Control
类(是基类Control
类,或衍生物之一,如OptionsControl
or ClickableControl
).
问题是因为我反序列化成Control
,我获得了控件上的所有属性,除了Options
。或者如果我尝试反序列化一个Url
and UrlTarget
,我只获取基本 Control 属性而不是 URL 属性。我认为 C# 会处理将反序列化对象转换为 OptionsControl 或 ClickableControl,但我想这是不正确的?我需要做什么才能使 DocumentDB 中的 JSON 对象正确序列化并变成OptionsControl
(具有选项属性)而不仅仅是基本控件?