C# 如何在XML配置文件中获取变量属性集?

C# 如何在XML配置文件中获取变量属性集?,c#,.net,xml,C#,.net,Xml,我正在执行的每个模式都有稍微不同的行为,因此我在设置配置xml文件中定义的atribute对于每个模式都可能不同 以这个xml为例 <MyFunction Mode="Mode1" > <ModeSettings ModeRange="all" ModeId="12"> </MyFunction > 仅适用于不同模式的设置 public class ModeSettings { [XmlAttribute("ModeRange")]

我正在执行的每个模式都有稍微不同的行为,因此我在设置配置xml文件中定义的atribute对于每个模式都可能不同

以这个xml为例

 <MyFunction Mode="Mode1" >
    <ModeSettings ModeRange="all" ModeId="12">
 </MyFunction >
仅适用于不同模式的设置

public class ModeSettings
{
    [XmlAttribute("ModeRange")]
    public string Range { get; set; }

[XmlAttribute("ModeId")]
    public int id { get; set; }
}

例如,ModeId属性可能不适用于所有模式。如何在XML和配置类中处理此问题?

将id设为可为null int,并为不应具有ModeId的模式提供nullattribute@SergeyBerezovskiy我知道你应该采取行动,那也行吗?
public class ModeSettings
{
    [XmlAttribute("ModeRange")]
    public string Range { get; set; }

}
public class ModeSettings
{
    [XmlAttribute("ModeRange")]
    public string Range { get; set; }

[XmlAttribute("ModeId")]
    public int id { get; set; }
}