1

I'm trying to create a custom C# Validation Attribute(without sealed keyword) for Data Annotation.

 public class MyValidatorAttribute : ValidationAttribute
 {
 }

But Microsoft page here says "Make the class not inheritable." why?

Do I overlooked something by allowing "MyValidatorAttribute" class as inheritable?

Richard Garside
  • 87,839
  • 11
  • 80
  • 93
191180rk
  • 735
  • 2
  • 12
  • 37

1 Answers1

1

According to this code analysis rule it is for performance reasons.

When retrieving custom attributes .NET will normally search the inheritance hierarchy and this can add an overhead that may not be required.

This would not stop you creating an abstract attribute that several sealed implementations inherited from.

Richard Garside
  • 87,839
  • 11
  • 80
  • 93