Accessing calling object from MethodCallExpression
<p>I'm trying to learn about Expression trees, and I've created a method that takes an</p>

<pre><code>Expression&lt;Func&lt;bool&gt;&gt;
</code></pre>

<p>and executes it if it satisfies some conditions - see the code below.</p>

<pre><code>        private static void TryCommand(Expression&lt;Func&lt;bool&gt;&gt; expression)
        {
            var methodCallExpression = expression.Body as MethodCallExpression;
            if (methodCallExpression == null)
            {
                throw new ArgumentException("expression must be a MethodCallExpression.");
            }

            if (methodCallExpression.Object.Type != typeof (MyClass))
            {
                throw new ArgumentException("expression must be operating on an instanceof MyClass.");                
            }

            var func = expression.Compile();
            var success = func.Invoke();

            if(!success)
            {
                Console.WriteLine(methodCallExpression.Method.Name + "() failed with error code " + (func.Target as MyClass).GetError());
            }
        }
</code></pre>

<p>The problem that</p>

<pre><code>(func.Target as MyClass)
</code></pre>

<p>is null. Clearly I'm doing something wrong! How do I access the instance that the method is operating on?</p>
