Exemplo n.º 1
0
 protected void AssertBuildable(NewBuilderPhase phase)
 {
     if (phase <= _flushedActionsPhase)
     {
         throw new Exception("Attempt to modify builder too late!");
     }
 }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        public void DoneBuilding(NewBuilderPhase phase)
        {
            if (phase <= _addedActionsPhase)
            {
                throw new Exception("Attempt to finalize builder too late!");
            }

            _addedActionsPhase = phase;
        }
Exemplo n.º 5
0
 protected ILazy <U> NewLazy <U>(NewBuilderPhase phase, Func <U> generator)
 {
     return(_lazy.New <U>(() => { Force(phase); return generator(); }));
 }
Exemplo n.º 6
0
 public void Force(NewBuilderPhase phase)
 {
     FlushActions(phase);
 }