2 回答
TA贡献1798条经验 获得超3个赞
选项1
实现此目的的一种方法是在 I2C 中公开接受操作的方法。这将允许 I2C 实例(它是LowLevelController 中定义的私有类)调用 Controller.Run。例如,
private class I2C
{
public I2C()
{
}
public void RunBase(Action execute)
{
execute.Invoke();
}
}
现在您可以将 RunBase 执行为
public void Computate()
{
var i2c = new I2C();
i2c.RunBase(()=>base.Run());
}
选项2
另一种选择是将 LowLevelController 的实例传递给 I2C 并调用 Controller.Run 方法
例子,
public class LowLevelController : ChildController
{
private class I2C
{
private LowLevelController _parent;
public I2C(LowLevelController parent)
{
_parent = parent;
}
public void RunBase()
{
_parent.Run();
}
}
public void Computate()
{
var i2c = new I2C(this);
i2c.RunBase();
}
}
TA贡献1874条经验 获得超12个赞
我想你想要的很简单:
public class LowLevelController : ChildController {
private class I2C {
public I2C(LowLevelController outerInstance) {
OuterInstance = outerInstance;
}
private LowLevelController OuterInstance { get; }
private void DoSomething() {
OuterInstance.Run();
}
}
}
- 2 回答
- 0 关注
- 115 浏览
添加回答
举报