2 回答

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
選項(xiàng)1
實(shí)現(xiàn)此目的的一種方法是在 I2C 中公開(kāi)接受操作的方法。這將允許 I2C 實(shí)例(它是LowLevelController 中定義的私有類)調(diào)用 Controller.Run。例如,
private class I2C
{
public I2C()
{
}
public void RunBase(Action execute)
{
execute.Invoke();
}
}
現(xiàn)在您可以將 RunBase 執(zhí)行為
public void Computate()
{
var i2c = new I2C();
i2c.RunBase(()=>base.Run());
}
選項(xiàng)2
另一種選擇是將 LowLevelController 的實(shí)例傳遞給 I2C 并調(diào)用 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貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
我想你想要的很簡(jiǎn)單:
public class LowLevelController : ChildController {
private class I2C {
public I2C(LowLevelController outerInstance) {
OuterInstance = outerInstance;
}
private LowLevelController OuterInstance { get; }
private void DoSomething() {
OuterInstance.Run();
}
}
}
- 2 回答
- 0 關(guān)注
- 166 瀏覽
添加回答
舉報(bào)