TypeBuilder tb = // create TypeBuilder instance tb.DefineField("name", typeof(string), FieldAttributes.Public); tb.DefineField("age", typeof(int), FieldAttributes.Public); Type newType = tb.AsType();
TypeBuilder tb = // create TypeBuilder instance tb.AddInterfaceImplementation(typeof(IExampleInterface)); Type newType = tb.AsType();This code creates a new TypeBuilder instance and adds an implementation for the IExampleInterface interface. The AsType method is called to create a new type from the TypeBuilder instance. The TypeBuilder class is part of the System.Reflection.Emit namespace, which is included in the .NET Framework Class Library.