Reflecting Attributes

Attributes are about applications’ metadata. Because of this, you can use reflection (refer to Chapter 44, “Reflection,” for details) to check whether a type recurs to custom attributes and investigate metadata (that is, application information). To accomplish this, you invoke the System.Reflection.MemberInfo.GetCustomAttributes and System.Reflection.Attributes.GetCustomAttributes shared methods. The first one returns all attributes applied to the specified type; the second one returns an array of custom attributes applied to an assembly, a type or its members, and method parameters. The following is the most basic example for retrieving information about attributes applied to members of the Document class:

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.