Phase 16 of 30 · Topic 16.1

Type Metadata Tables, MemberInfo & Assembly Reflection

1Concept

Assemblies store type definitions in structured metadata tables (TypeDef, MethodDef, ParamDef). Reflection traverses these tables at runtime to discover types and inspect signatures.

2Architecture Diagram

Assembly Metadata Tables
├── TypeDef Table   ──> Class Name, Flags, Extends
├── MethodDef Table ──> Method Name, Signature, IL RVA Offset
└── ParamDef Table  ──> Parameter Name, Attributes

3Code Example

C# 13 & .NET 9
using System;
using System.Reflection;

public class ReflectionMetadataDemo
{
    public string ServiceName { get; set; } = "AuthService";
    public void Start() => Console.WriteLine("Service Running.");

    public static void Main()
    {
        Type t = typeof(ReflectionMetadataDemo);
        Console.WriteLine($"Full Type: {t.FullName}");
        Console.WriteLine($"Assembly:  {t.Assembly.GetName().Name}");

        PropertyInfo? prop = t.GetProperty("ServiceName");
        Console.WriteLine($"Property Discovered: {prop?.Name} ({prop?.PropertyType.Name})");
    }
}

4Expected Output

Full Type: ReflectionMetadataDemo
Assembly:  Frontend
Property Discovered: ServiceName (String)

5Key Takeaways

  • Reflection inspects assembly metadata tables loaded into memory.
  • `typeof(T)` resolves at compile time; `obj.GetType()` resolves dynamically at runtime.
  • Reflection queries are relatively slow; cache `PropertyInfo` and `MethodInfo` references.