Given the following set of classes:
public class MyClass
{
public int MyInt { get; set; }
}
public class ObjectProcessor
{
public int ProcessObject(MyClass myClass)
{
return myClass.MyInt ++;
}
}
public class Runner
{
public void Run()
{
var classToPass = new MyClass();
FuncExecutor.ExecuteAction<MyClass>(x => x.ProcessObject(classToPass));
}
}
public static class FuncExecutor
{
public static void ExecuteAction<T>(Expression<Func<ObjectProcessor, int>> expression)
{
}
}
From the method ExecuteAction, how can I get a link to the instance classToPassthat was passed in ProcessObject?
EDIT: The comments emphasized the difficulty of trying to parse expression trees, which can vary greatly in their composition.
However, in this particular case, there are two facts that significantly reduced this option:
ProcessObject will take only one parameter.- The type of parameter is known in advance.
Changed code to express this.
source
share