Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MirzaMerdovic/a4edc57219a7634479f3ae5482754dfc to your computer and use it in GitHub Desktop.
Save MirzaMerdovic/a4edc57219a7634479f3ae5482754dfc to your computer and use it in GitHub Desktop.
private static TDelegate BuildHandler<TDelegate>(TServiceImpl instance, string methodName)
{
MethodInfo method = instance.GetType().GetMethod(methodName);
IEnumerable<ParameterExpression> parameters = method.GetParameters().Select(x => Expression.Parameter(x.ParameterType)).ToList();
var call = Expression.Call(Expression.Constant(instance), method, parameters);
var func = Expression.Lambda<TDelegate>(call, false, parameters).Compile();
return func;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment