I have these properties (A,B) :
[DataType(DataType.MultilineText)]
[Required(ErrorMessage = "A is required"), DisplayName("A")]
[StringLength(Constants.MaximunStringSize)]
public string A { get; set; }
[DataType(DataType.MultilineText)]
[Required(ErrorMessage = "B is required"), DisplayName("B")]
[StringLength(Constants.MaximunStringSize)]
public string B { get; set; }
I can create a class that "inherits" all the attributes (DataType, Required, StringLength, DisplayName) and the set through its constructor?. By example:
[MyAttribute("A","A is required")]
public string A { get; set; }
[MyAttribute("B","B is required")]
public string B { get; set; }
In general, no.
However, for validation attributes, you could create your own validation attribute that contains all of the logic in the existing attributes.
To emulate [DataType], you'll need to implement IMetadataAware.
There is no multiple inheritance in C#, so no, you can't do this.
You can, however write your own Attribute that incorporates all the functionality of those attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With