Appendix C. Reflection and Attributes

Reflection is the programmatic act of reading the metadata associated with a type. You can read the metadata to learn what the type is and what is it made of (i.e., methods, properties, base classes). Reflection services are defined in the System.Reflection namespace. Reflection is most useful in conjunction with attributes, which are a way of adding information to a type and affecting the type’s behavior. Reflection also has another esoteric feature not covered in this appendix: it allows you to define new types during runtime and emit the corresponding IL code and metadata (using the services found in the System.Reflection.Emit namespace). This appendix starts by reviewing some key .NET reflection techniques and then focuses on using and defining attributes.

Get Programming .NET Components, 2nd Edition 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.