开发者

Validate private properties using ValidationAttributes in .net 4

I have classes which get private properties set via the constructor.

I would then like to run the following code from a base class to check if the passed values are ok: ValidationContext context = new ValidationContext(this, n开发者_如何学Pythonull, null);

ValidationResults = new List();

if (!System.ComponentModel.DataAnnotations.Validator.TryValidateObject(this, context, ValidationResults, true))
{
    this.Success = false;
    this.StatusCode = CommandStatusCode.ValidationFailed;
    return false;
}
return true;

Problem is, the TryValidateObject only validates public properties. Is there any way of getting private properties validated?


I would use code contracts on your constructor's arguments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜