在调用创建编译表达式时,我试图在生成的编译委托上调用 CreateDelegate,但遇到 NotSupportedException,解释是:派生类必须提供实现。如何为已编译的方法创建委托?
public delegate int AddOne(int input);
void Main()
{
var input = Expression.Parameter(typeof(int));
var add = Expression.Add(input,Expression.Constant(1));
var lambda = Expression.Lambda(typeof(AddOne),add,input);
var compiled = (AddOne)lambda.Compile();
compiled.Method.CreateDelegate(typeof(AddOne));
}