0

我正在使用第 3 方 XSD 及其糟糕的东西。但是,所有枚举都没有正确反序列化,它们默认为第一个值。

这是其中一个枚举的示例

public enum LoanIdentifierBase
{
    NotSet,
    AgencyCase,
    InvestorCommitment,
    InvestorContract,
    InvestorLoan,
    InvestorWorkoutCase,

这是使用此枚举的类

public class LoanIdentifierEnum : BaseClass
{
    [XmlAttribute("SensitiveIndicator")]
    public bool SensitiveIndicator { set; get; }

    [XmlIgnore]
    public bool SensitiveIndicatorSpecified { set; get; }

    [XmlAttribute(Form = XmlSchemaForm.Qualified, Namespace = "http://www.w3.org/1999/xlink", DataType = "NCName")]
    public string label { set; get; }

    [XmlAnyAttribute]
    public XmlAttribute[] AnyAttr { set; get; }


    public LoanIdentifierBase Values { set; get; }
}

我已经尝试了几个标签和排列,但无论我做什么,这些值都会返回为未设置。

这是与此相关的导入文件

在此处输入图像描述

4

1 回答 1

0

这是一个愚蠢的答案,但它有效

public LoanIdentifierBase Values { set; get; }

变成

[XmlText]
public string RealValue { set; get; }

public LoanIdentifierBase Value => (LoanIdentifierBase) Enum.Parse(typeof(LoanIdentifierBase), RealValue);

这允许值反序列化为正确的枚举值

于 2018-04-25T15:38:34.530 回答