How can I create a "decorator abbreviation" in ASP.net Core

Viewed 97

I am working on a project with a lot of models where I need the same validation with localized error messages happen at a couple of different places. Right now I decorate the corresponding properties with

        [RegularExpression(Bla, ErrorMessageResourceType = typeof(Blub), ErrorMessageResourceName = Blablablub)] 
        public int SomeInt { get; set; }

How can I specify a shorthand for this with a custom validation attribute? What I want is something like

        [MyRegularExpressionDecorator] 
        public int SomeInt { get; set; }

Any input is greatly appreciated. Thanks!

1 Answers
public class MyRegularExpressionDecoratorAttribute : RegularExpressionAttribute
{
    public MyRegularExpressionDecoratorAttribute()
        : base("bla") 
    {
        ErrorMessageResourceType = typeof(Blub);
        ErrorMessageResourceName = "Blablablub";
    }
}
Related