As @_gile has already mentioned, the code I posted here a little over 10 years ago, that solves your problem, has been deleted by Autodesk.
Because I harbor no contempt for users of old/outdated releases of AutoCAD, Here it is again:
using System.Reflection;
using System;
using System.Linq.Expressions;
namespace Autodesk.AutoCAD.EditorInput
{
public static class EditorInputExtensionMethods
{
public static PromptStatus Command(this Editor editor, params object[] args)
{
if(editor == null)
throw new ArgumentNullException("editor");
return runCommand(editor, args);
}
static Func<Editor, object[], PromptStatus> runCommand = Generate;
static PromptStatus Generate(this Editor editor, params object[] arguments)
{
MethodInfo method = typeof(Editor).GetMethod("RunCommand",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
var instance = Expression.Parameter(typeof(Editor), "instance");
var args = Expression.Parameter(typeof(object[]), "args");
runCommand = Expression.Lambda<Func<Editor, object[], PromptStatus>>(
Expression.Call(instance, method, args), instance, args)
.Compile();
return runCommand(editor, arguments);
}
}
}