Task StateAccessor <TInstance> .Set(InstanceContext <TInstance> context, State <TInstance> state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            var previous = _property.Get(context.Instance);

            if (state.Name.Equals(previous))
            {
                return(TaskUtil.Completed);
            }

            _property.Set(context.Instance, state.Name);

            State <TInstance> previousState = null;

            if (previous != null)
            {
                previousState = _machine.GetState(previous);
            }

            return(_observer.StateChanged(context, state, previousState));
        }
Пример #2
0
        Task StateAccessor <TInstance> .Set(InstanceContext <TInstance> context, State <TInstance> state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            var stateIndex = _index[state.Name];

            var previousIndex = _property.Get(context.Instance);

            if (stateIndex == previousIndex)
            {
                return(TaskUtil.Completed);
            }

            _property.Set(context.Instance, stateIndex);

            var previousState = _index[previousIndex];

            return(_observer.StateChanged(context, state, previousState));
        }