c# - .Net - DataAnnotations - Validate 2 dependent DateTime -


let got following classes:

public class post  {     public date begindate { get; set; }      [validate2date(begindate, enddate, errormessage = "end date have occurs after begin date")]     public date enddate { get; set; } }  public class validate2dates : validationattribute {     public validate2dates(datetime a, datetime b)     { ... }      public override bool isvalid(object value)     {         // compare date , return false if b <     } } 

my problem how use custom validate2dates attribute because can't that:

[validate2date(begindate, enddate, errormessage = "end date have occurs before begin date")] 

i got following error:

an object reference required non-static field, method, or property '...post.begindate.get' c:...\post.cs

you can't use attribute that. attribute parameters restricted constant values.

imo better solution provide method on class implements check , can called through business logic validation interface of liking.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -