I'm writing a Visual Studio extension. I have a C# class representing an options page. An option is represented by a public property, like this:
public class OptionsPageGeneral : DialogPage
{
[Range(1, 100)]
[Category("Misc")]
[DisplayName("Integer option")]
public string IntOption { get; set; }
...
}
I'm trying to use the RangeAttribute
validation attribute to restrict user input. However, for the given code, user still can input any value, not only from [1; 100] range.
I've seen lots examples of ValidationAttribute usage, but all for ASP.NET MVC projects. Is it true this attribute is only applicable in that context?
Anyway, how can I validate user input done in options page? I know I can simply override the property set
method, but validation attributes require much less code to write and can be reused for the similar properties.