One of the coolest things in the .NET framework has to be Reflection. System.Reflection.Emit gives you the ability to build and execute code at runtime. This sample includes a class, DllRegServer, that uses Reflection Emit to create another class with two public PInvoke methods, DllRegisterServer and DllUnregisterServer, used to register/unregister a COM DLL. The path to the DLL implementing the methods has to be set at runtime.
The DllRegServer class is then used to create a utility called Regsvr.exe, Similar to the Regsvr32.exe app included with Windows. VB.NET and C# source code is included