Provides functionality for generating .NET types and assemblies runtime.
When wrapping delegates and types, the delegate and method parameters can be converted to constructor parameters and properties.
Note: The intendent use case is not proxy classes and the generated types don't inherit the original types.
var code = @"public class MyClass
{
public void RunThings()
{
var y = 0;
var a = 1;
a = y + 10;
}
}";
var assembly = _generator.GenerateAssembly(code);
var type = assembly.GetExportedTypes().Single();
var converter = new DelegateToTypeConverter();
var type = converter.CreateType(new Func<int, bool>(i =>
{
System.Console.WriteLine($"Hello from delegate. I is {i}");
return true;
}));
dynamic instance = Activator.CreateInstance(type);
var result = instance.Run(25);
This template is MIT licensed.