RegularExpressionAttribute和自动属性上的其他验证器是否有效?

时间:2017-08-20 06:19:20

标签: c# validation code-generation xsd2code

我正在使用xsd2code从架构生成类。我怎么会怀疑自动属性是否可以验证值?

因为如果我在xsd2code中启用MATLAB/bin/glnxa64/,这就是我为Regex限制的成员所获得的。

AutomaticProperties

禁用[System.Xml.Serialization.XmlAttributeAttribute(DataType="token", AttributeName="color")] [System.ComponentModel.DataAnnotations.RegularExpressionAttribute("#[\\dA-F]{6}([\\dA-F][\\dA-F])?")] public string Color { get; set; }

AutomaticProperties

看来这些并不等同。所以我认为它是xsd2code中的一个错误,或者我可能误解了一些东西。什么是第二生成代码的目的?

我认为[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; } } 也会验证自动属性。

0 个答案:

没有答案