i'm trying to write a function that checks the methods with a specific attribute and collects info about them. Then, i need to compile them into expression so it's overhead will be minimal. But when i try to run my function, i get error that i put into the header.
My code is:
MethodInfo? method_info = handler_class.GetType().GetMethod("Handler");
if (method_info == null) continue;
ParameterInfo[] prms = method_info.GetParameters();
Type param_type = prms[0].ParameterType;
ParameterExpression[] prm_exprs = new ParameterExpression[] {
Expression.Parameter(param_type, "data")
};
MethodCallExpression method_expression = Expression.Call(
Expression.Constant(handler_class),
method_info,
prm_exprs
);
Debug.WriteLine(method_expression.ToString());
Expression<Action<object>> le = Expression.Lambda<Action<object>>(
method_expression,
"HandlerCaller",
true,
prm_exprs
);
Action<object> handler = le.Compile();
Aucun commentaire:
Enregistrer un commentaire