I'm using xsd2code for generating classes from schema. how ever I'm suspicious that auto properties can validate values or not?
because if I enable AutomaticProperties
in xsd2code here is what I get for member with Regex restriction.
[System.Xml.Serialization.XmlAttributeAttribute(DataType="token", AttributeName="color")]
[System.ComponentModel.DataAnnotations.RegularExpressionAttribute("#[\\dA-F]{6}([\\dA-F][\\dA-F])?")]
public string Color { get; set; }
And when AutomaticProperties
is disabled
[System.Xml.Serialization.XmlAttributeAttribute(DataType="token", AttributeName="color")]
[System.ComponentModel.DataAnnotations.RegularExpressionAttribute("#[\\dA-F]{6}([\\dA-F][\\dA-F])?")]
public string Color
{
get
{
return this._color;
}
set
{
System.ComponentModel.DataAnnotations.ValidationContext validatorPropContext = new System.ComponentModel.DataAnnotations.ValidationContext(this, null, null);
validatorPropContext.MemberName = "Color";
Validator.ValidateProperty(value, validatorPropContext);
this._color = value;
}
}
It seems these are not equivalent. so I think its a bug in xsd2code or maybe I'm misunderstanding something. whats the purpose of second generated code?
I thought RegularExpressionAttribute
would also validate automatic properties too.