Under the hood
What does exactly happen to our custom attribute when the compiler compiles
the class User? The simple explanation goes like this: when the compiler encounters
the ValidLength specification in class User, it looks for a class ValidLength
but it can find one. It then searches for a class ValidLengthAttribute and it
finds one. Next, the compiler verifies if the target of ValidLengthAttribute
is valid. It then verifies if there is a constructor whose signature matches
the parameters used in the attribute specification. If a named parameter is
used, it also verifies the existence of field or property by that name. The
compiler also verifies if it is able to create an object of ValidLengthAttribute
class. If no error is encountered, the attribute parameter values are stored
along with other metadata information of the class.