When using NHibernate, you define your entites with virtual methods, and NHibernate will create a proxy object that tracks changes to your object.
In Moq, the framework will magically create a derived type from an interface or a base class. e.g.
var mock = new Mock<IFoo>();
IFoo magicFoo = mock.Object;
This is really cool. How do these frameworks do it? Do they use reflection, generics, some kind of dynamic compilation, or something else?
I realize these are both open source projects, and I could go spelunking through the code, but I'd like to have a concise answer here - possibly with alternatives.