Last active
October 16, 2021 11:56
-
-
Save pawelel/280a39f57a76dce390c5af0e596a7f22 to your computer and use it in GitHub Desktop.
Custom Range attribute for System.ComponentModel.DataAnnotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | |
public class RangeUntilCurrentYearAttribute : RangeAttribute | |
{ | |
public RangeUntilCurrentYearAttribute(int minimum) : base(minimum, DateTime.Now.Year) | |
{ | |
} | |
} | |
// And use it like this: | |
//public class Foo | |
// { | |
// [RangeUntilCurrentYear(1900, ErrorMessage = "Please enter a valid year")] | |
// public int Year { get; set; } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment