No. There is no such native annotation. You can make your own, which will take as a paramter the name of the property on which the validation depends, and then when applying, pass the appropriate property name.
The way to do this is to create a custom annotation class deriving from ValidationAttribute
, and making a constructor which takes as a parameter the name of the dependent property, and then override the IsValid
method, in which you get the value of the dependent property using reflection, and write your custom validation logic.
Now, this will work for server side validation. But you need to do a lot more if you need client side validation as well, which is beyond the scope of this question.