.NET Array Dictionary List String 2D Async DataTable Dates DateTime Enum File For Foreach Format IEnumerable If IndexOf Lambda LINQ Parse Path Process Property Regex Replace Sort Split Static StringBuilder Substring Switch Tuple

C#: .NET

Reflection uses the type system. A compiled C# program is encoded into a relational database.
With reflection,
a program reads this metadata,
tests it with logic,
and makes decisions.


Fields. We search fields with the GetField and GetFields methods. We get all the fields in a class and display their values. Next we set the values of fields through reflection.

Field ReflectionSetValue

Methods. What should we do if we have the name of a method in string format and want to call the method? We can use GetMethod. Then we invoke the MethodInfo we acquire from it.

GetMethodMethodInfo Invoke

Properties. A property is a kind of method. We scan properties and mutate them using the reflection mechanism.
A special type,
must be used.

Property Reflection
About part

Types. The "Type" type is important when reflecting. We cover the GetType method that is found on the object type. GetType helps us discover the object hierarchy.

Class shapes

Assembly. In reflection, an assembly contains many types. With the Assembly class, we can access these types. This helps us analyze larger units of code.


Typeof. This operator uses reflection to return the Type of a variable. We use the typeof operator in most code that requires complicated reflection capabilities.


Sizeof. This operator exposes information about the implementation of types. It does not require the System.Reflection namespace. But it is related to reflection.


Default. This operator returns the default value for a type. It is used when developing classes such as generics. The default value of an int is zero.


Research. When a C# program is compiled, it is actually converted into a relational database. When the runtime starts, it reads this program data. It constructs further representations.

Expert .NET 2.0 IL Assembler

From .NET IL Assembler. "Structurally, metadata is a normalized relational database. This means that metadata is organized as a set of cross-referencing rectangular tables" (page 73).

Programs that use reflection can look inside themselves to see their inner workings. This capacity lends them unique and powerful features. But it also makes them slower, more complex.