我的XML配置文件的一部分看起来像这样
<Formatting Mode="Format1">
<FormatterSettings Range="Range1" Restriction="None" Padding="0" />
</Formatting>
<Formatting Mode="Format2">
<FormatterSettings Range="Range3" Restriction="None" Padding="0" />
</Formatting>
我的班级看起来像这样
public class Formatting
{
[XmlAttribute("Mode")]
public FormatterType Mode { get; set; }
public FormatterSettings FormatSettings { get; set; }
}
public class FormatterSettings
{
[XmlAttribute("Range")]
public CharacterRange CharRange { get; set; }
[XmlAttribute("Restriction")]
public CharacterRangeRestriction RestrictRange { get; set; }
[XmlAttribute("Padding")]
public int Padding { get; set; }
}
但我有一个只有一个设置的特殊格式化程序,所以我需要XML看起来像
<Formatting Mode="DateFormatter">
<FormatterSettings DateFormat="yyyyMMdd" />
</Formatting>
所以在那个特殊情况下,我的课程将是,没有其他设置,但我只想要一个课程,如果这甚至是可能的话。
public class FormatterSettings
{
[XmlAttribute("DateFormat")]
public string DateFormat{ get; set; }
}
我该怎么做?
答案 0 :(得分:0)
怎么样?
public class FormatterSettings
{
[XmlAttribute("Range")]
public CharacterRange CharRange { get; set; }
[XmlAttribute("Restriction")]
public CharacterRangeRestriction RestrictRange { get; set; }
[XmlAttribute("Padding")]
public int Padding { get; set; }
[XmlAttribute("DateFormat")]
public string DateFormat{ get; set; }
}