-
Book Overview & Buying
-
Table Of Contents
Metaprogramming in C#
By :
In .NET, everything we compile ends up inside what is called an assembly. This is the binary that holds the compiled code in the form of Intermediate Language (IL). Alongside this, there is metadata that goes with it to identify types, methods, properties, fields, and any other symbols and metadata.
All of these artifacts are discoverable through APIs, and it all starts with the System.Reflection namespace. Within this namespace, there are APIs that allow you to reflect on what’s running. In other languages, this is often referred to as introspection.
Looking at any instance of any type you’ll see that there is always a GetType() method you can call. This is part of the reflection capabilities and is implemented in the base type of Object, which all types implicitly inherit from.
The GetType() method returns a Type type that describes the capabilities of the particular type – its fields, properties, methods, and...