Skip to content
dreamcode
dreamcode
Map
Reflection
Lesson 19 of 21
+15 XP on finish
C# EXPERTChapter 6 · C# Expert

Reflection and custom attributes

Use Reflection via System.Reflection to inspect metadata at runtime. Retrieve types, read custom attributes, and instantiate objects or call methods dynamically.

Worked example
using System;
using System.Reflection;

class Program {
    static void Main() {
        Type t = typeof(Program);
        foreach (var method in t.GetMethods()) {
            Console.WriteLine(method.Name);
        }
    }
}

How it reads

  • typeof(T) retrieves the metadata definition for type T
  • Reflection enables dependency injection, serialization, and dynamic routing plugins
Cloud tip: Reflection is highly versatile but incurs a performance cost; cache type lookups where possible.

Check your understanding

0 / 2

Answer all 2 to complete this lesson and earn 15 XP.

  1. 1. Which namespace contains C# Reflection classes?
  2. 2. What is the cost of leaning heavily on Reflection?
Answer every question to unlock the next lesson.