早上好!问题是有关C#语言的序列化过程。在XML序列化中,有一个属性“ XmlChoiceIdentifierAttribute”,它提供了要反序列化/序列化的类型之间的选择。在此属性的构造函数中,我们传递一个属性名称,该名称存储用于选择的类型名称。 (此属性必须是枚举类型)。示例:
// The MyChoice field can be set to any one of
// the types below.
[XmlChoiceIdentifier("EnumType")]
[XmlElement("Word",typeof(string))]
[XmlElement("Number",typeof(int))]
[XmlElement("DecimalNumber",typeof(double))]
public object MyChoice;
// Don't serialize this field. The EnumType field
// contains the enumeration value that corresponds
// to the MyChoice field value.
[XmlIgnore]
public ItemChoiceType EnumType;
在此示例中,MyChoice的类型将取决于“ EnumType”属性。因此,处理方法是针对XML序列化。问题是,是否存在用于JSON序列化的XmlChoiceIdentifier属性的类似物?