0

I got XMLIgnoreAttribute, VARSpecified to ignore or ignore-able value.

But is there any attribute to specified must have a value ?

I found this Attributes That Control XML Serialization, but nothing useful.

class Test
{
    [XMLIgnore]
    public string IgnoredValue;

    [XMLAttribute]
    public string AnAttribute;

    // If 'AnAttribute' length < 5 will be ignored
    public bool AnAttributeSpecified{get {return AnAttribute.Length > 5;};}

    // For this, it must have a value, is there any attribute for this?
    public string Name;
}
wener
  • 7,191
  • 6
  • 54
  • 78
  • Are you saying you want to make sure users supply a non-null, non-empty value for `Name`? If they do try to assign one of those, do you want it to throw an exception or use a default value instead? – Chris Sinclair Sep 08 '13 at 13:50
  • Maybe the only way is I check the value by myself, if the value not match the rules, then throw an Exception instead. Actually ,I just want the XMLSerialize do this check. – wener Sep 08 '13 at 17:02
  • AFAIK, the `XmlSerializer` can't do these checks for you. However, it's trivial to do them yourself by using properties for your members and validating the values in the setter. – Chris Sinclair Sep 08 '13 at 19:29

0 Answers0