CSharp · Console
using System;
using System.Reflection;
using System.Reflection.Emit;
public abstract class Base
{
}
public class Program
{
public static void Main()
{
var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run);
var moduleBuilder = assemblyBuilder.DefineDynamicModule(Guid.NewGuid().ToString());
var typeName = "Child";
var typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout, typeof(Base));
typeBuilder.DefineDefaultConstructor(MethodAttributes.Private | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
var assembly = typeBuilder.Assembly;
try
{
assembly.GetTypes();
}
catch (ReflectionTypeLoadException exception)
{
Console.WriteLine(exception.Message);
}
}
}