I’ve the following Attributes defined on my Name field:
[Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(MyResources))]
[Display(Order = 0, Name = ResXStrings.UserName, ResourceType = typeof(MyResources))]
public string Name { get; set; }
I want to create a custom Attribute which looks like this:
[MyAttribute(DisplayName = "Username", ErrorMessage = "ValidationErrorRequiredField", ResourceType = typeof(MyResources))]
public string Name { get; set; }
which defines in code the other two (Required and Display) attributes.
How to implement this ?
UPDATE
It’s not possible.
Thanks to all people who helped answering my question.
I don’t think you can. Since consumers of the attributes often find them by type your new attribute would have to be both a RequiredAttribute and a DisplayAttribute. C# doesn’t support multiple inheritance so there is no way to make such a class.