.NET CLR Concepts – Tables

Introduction

The Common Language Runtime (CLR) stores metadata about assemblies, types, members, and other constructs in a series of structured metadata tables. These tables are the foundation for reflection, type safety, and the execution engine.

Key Metadata Tables

TablePurposePrimary Columns
ModuleDefines each module in an assemblyGeneration, Name, Mvid
TypeDefDescribes each type defined in the moduleFlags, Name, Namespace, Extends, FieldList, MethodList
MethodDefHolds information about each methodRVA, ImplFlags, Flags, Name, Signature, ParamList
FieldStores field definitionsFlags, Name, Signature
MemberRefReferences to members defined outside the current moduleClass, Name, Signature
CustomAttributeCustom attribute data applied to metadata entitiesParent, Type, Value

Sample Metadata Table Access via Reflection

// Display TypeDef table information for the current assembly
using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        var asm = Assembly.GetExecutingAssembly();
        foreach (var type in asm.DefinedTypes)
        {
            Console.WriteLine($"Type: {type.FullName}");
            Console.WriteLine($"  Base Type: {type.BaseType}");
            Console.WriteLine($"  Methods:");
            foreach (var m in type.DeclaredMethods)
                Console.WriteLine($"    {m.Name} ({m.Attributes})");
        }
    }
}

Understanding Table Relationships

Metadata tables are linked through indexes. For example, the MethodDef table's ParamList column points into the Param table, defining the method's parameters. These relationships enable the CLR to navigate from a type to its members efficiently.

Further Reading