I have the following classes Ruleand Ruleset:
[XmlInclude(typeof(OrRule))]
[XmlInclude(typeof(AndRule))]
[XmlInclude(typeof(EmptyRule))]
[XmlInclude(typeof(MatchRule))]
public class Rule {}
[XmlType("Or")]
public class OrRule
{
public Rule[] Operands { get; set; }
}
[XmlType("And")]
public class AndRule
{
public Rule[] Operands { get; set; }
}
[XmlType("Empty")]
public class EmptyRule {}
[XmlType("Match")]
public class MatchRule
{
public string Regex { get; set; }
}
public class Ruleset
{
public string Name { get; set; }
[XmlArrayElement(typeof(OrRule))]
[XmlArrayElement(typeof(AndRule))]
[XmlArrayElement(typeof(EmptyRule))]
[XmlArrayElement(typeof(MatchRule))]
public Rule[] Rules { get; set; }
}
(I hope everything is fine with me - this is a radically simplified example, not the actual code.) They serialize like this:
<Ruleset Name="PasswordEmptyAllowed">
<Rules>
<Or>
<Operands>
<Empty />
<And>
<Operands>
<Match Regex="\d" />
<Match Regex="[a-záéíóöőúüű]" />
<Match Regex="[A-ZÁÉÍÓÖŐÚÜŰ]" />
</Operands>
</And>
</Operands>
</Or>
</Rules>
</Ruleset>
Additional tags <Rules>and <Operands>in my opinion a rather ugly, and they degrade readability. Is there any way to fix them?
Like this:
<Ruleset Name="PasswordEmptyAllowed">
<Or>
<Empty />
<And>
<Match Regex="\d" />
<Match Regex="[a-záéíóöőúüű]" />
<Match Regex="[A-ZÁÉÍÓÖŐÚÜŰ]" />
</And>
</Or>
</Ruleset>
source
share