Declaring a view component is too easy!

From the documentation:

A view component class can be created by any of the following:

  • Deriving from ViewComponent
  • Decorating a class with the [ViewComponent] attribute, or deriving from a class with the [ViewComponent] attribute
  • Creating a class where the name ends with the suffix ViewComponent

The first two are explicit. In fact, if the ViewComponent is decorated with the [ViewComponent], the type could selected with a simple check.

The last one is a bit more troublesome, as it could select types that were not supposed to. So there is another rule:

To prevent a class that has a case-insensitive ViewComponent suffix from being treated as a view component, decorate the class with the [NonViewComponent] attribute.

So, not only the last rule require more code to identity a view component, it has to include code to prevent unwanted selection, and, to do so, we would introduces an undesirable coupling by decoratign our class with an attribute unrelated to the class itself.

References & Useful Links

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.