private SecondState() { if (_instance != null) { return; } _instance = this; }
public void Work() { IState firstState = new FirstState(); IContext context = new Context(firstState); for (int i = 0; i < 4; i++) { context.DoSomething(); context.DoSomething1(); Console.WriteLine(); } IState secondState = new SecondState(); context.SetState(secondState); context.DoSomething(); context.DoSomething1(); }
public BusyContainerStackViewModel(ILogger logger) { Logger = logger ?? throw new ArgumentNullException(nameof(logger)); Content = new StackBusyState(); FirstStateCommands = new List <IUICommand> { new RelayUICommand(() => FirstState = Content.Push("First state title", "First state description"), () => FirstState == null) { Title = "Initialize" }, new RelayUICommand(() => { FirstState.Dispose(); FirstState = null; }, () => FirstState != null) { Title = "Reset" }, new RelayUICommand(async() => await PayloadBackgroundOperation(FirstState), () => FirstState != null) { Title = "Payload" } }; SecondStateCommands = new List <IUICommand> { new RelayUICommand(() => SecondState = Content.Push("Second state title", "Second state description"), () => SecondState == null) { Title = "Initialize" }, new RelayUICommand(() => { SecondState.Dispose(); SecondState = null; }, () => SecondState != null) { Title = "Reset" } }; ThirdStateCommands = new List <IUICommand> { new RelayUICommand(() => ThirdState = Content.Push("Third state title", "Third state description"), () => ThirdState == null) { Title = "Initialize" }, new RelayUICommand(() => { ThirdState.Dispose(); ThirdState = null; }, () => ThirdState != null) { Title = "Reset" } }; }
/// <param name="nextState">The next Coroutine in the stack to be run</param> protected void SetState(SecondState newState, StateMethod nextState) { StateDefaults(); m_NextState = newState; StartCoroutine(m_NextState(nextState)); }