vendredi 2 octobre 2015

C# - if else in Data Annotations

This is about Data Annotations in C#.

I have a class called MyClass. There I will be having two properties.

class MyClass
{
         private string _propName;
         public string PropName
         {
              get {return _propName;}
              set {_propName=value;}
         }

         private string _propVal;
         public string PropVal
         {
              get {return _propVal;}
              set {_propVal=value;}
         }
}

I have a MS SQl table which contains data for propName and relevant propValue. I need to have validations using DataAnnotations. Each and every _propName need to have different validations.

My question is : How do I add different validations/data annotations to the class structure I have mentioned above ? I was wondering whether or not there is some way to specify if-else conditions in Data Annotations ?

        if "this propertyname"
               validation 1
        else if "that property name"
               validation 1

Can someone help ?

Aucun commentaire:

Enregistrer un commentaire