16.6. Creating new types during runtime

System.Reflection.Emit contains classes such as AssemblyBuilder, ModuleBuilder, TypeBuilder, and MethodBuilder which are used to create new types during runtime. Rarely used in conventional programming, the ability to create new Types during runtime may be useful when you want to dynamically create new proxy classes for remote operations.

Since this is an advanced topic, I will give only a simple code example to give a clue as to which classes to use. Refer to the API documentation for more information about each class in System.Reflection.Emit.

 1: using System; 2: using System.Reflection; 3: using System.Reflection.Emit; 4: 5: public class TestClass{ 6: 7: public static Type CreateType (){ 8: 9: AppDomain ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.