12Reflection, Metadata, and Source Generators

INSPECTING CODE AT RUNTIME AND DYNAMIC PROGRAMMING

This chapter focuses on custom attributes, reflection, dynamic programming, and source code generation during the build process with C# 9 source generators. Custom attributes are mechanisms that enable you to associate custom metadata with program elements. This metadata is created at compile time and embedded in an assembly. Reflection is a generic term that describes the capability to inspect and manipulate program elements at runtime. For example, reflection allows you to do the following:

  • Enumerate the members of a type
  • Instantiate a new object
  • Execute the members of an object
  • Find out information about a type
  • Find out information about ...

Get Professional C# and .NET, 2021st 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.