protected void AssertBuildable(NewBuilderPhase phase) { if (phase <= _flushedActionsPhase) { throw new Exception("Attempt to modify builder too late!"); } }
private void FlushActions(NewBuilderPhase phase) { for (NewBuilderPhase phaseToRun = _flushedActionsPhase; phaseToRun <= phase; _flushedActionsPhase = phaseToRun, phaseToRun = (NewBuilderPhase)(phaseToRun + 1)) { if (phaseToRun == NewBuilderPhase.Final) { break; } if (phaseToRun > _addedActionsPhase) { throw new Exception("Attempt to flush builder too early"); } if (_actionForPhase == null) { continue; } var action = _actionForPhase[(int)phaseToRun]; if (action == null) { continue; } _actionForPhase[(int)phaseToRun] = null; _debugRunningActionsPhase = phaseToRun; action(); _debugRunningActionsPhase = NewBuilderPhase.Initial; } }
public void AddAction(NewBuilderPhase phase, Action action) { if (phase <= _addedActionsPhase && (phase <= NewBuilderPhase.Body)) { throw new Exception("Attempt to add action too late!"); } if (phase <= _flushedActionsPhase) { throw new Exception("Attempt to add action too late!"); } if (_actionForPhase == null) { _actionForPhase = new Action[(int)NewBuilderPhase.Final]; } var oldAction = _actionForPhase[(int)phase]; var newAction = action; if (oldAction != null) { newAction = () => { oldAction(); action(); }; } _actionForPhase[(int)phase] = newAction; }
public void DoneBuilding(NewBuilderPhase phase) { if (phase <= _addedActionsPhase) { throw new Exception("Attempt to finalize builder too late!"); } _addedActionsPhase = phase; }
protected ILazy <U> NewLazy <U>(NewBuilderPhase phase, Func <U> generator) { return(_lazy.New <U>(() => { Force(phase); return generator(); })); }
public void Force(NewBuilderPhase phase) { FlushActions(phase); }