我们有一个 Command 类,它在构造函数中将 Action 作为参数,我们需要从该 Action 访问 Command 类的一些方法。有没有办法实现这一目标?
public class Command
{
private readonly Action _action;
public Command(Action action)
{
_action = action;
}
public void Execute()
{
_action();
}
public void AnotherMethod()
{
}
}
static void Main()
{
var command = new Command(() =>
{
// do something
// ?? how to access and call
// command.AnotherMethod(); ??
// do something else
});
....
}