コード例 #1
0
        public static object Unpack(object[] args, Type argType, int index)
        {
            Enforce.ArgumentNotNull(args, "args");

            if (args.Length <= index)
            {
                throw new ArgumentException(
                          string.Format("An argument of type {0} is required in position {1}.", argType, index));
            }

            var arg = args[index];

            if (arg != null && !argType.IsInstanceOfType(arg))
            {
                throw new ArgumentException(
                          string.Format("The argument in position {0} is of type {1} but must be of type {2}.", index, arg.GetType(), argType));
            }

            return(arg);
        }
コード例 #2
0
 /// <summary>
 /// Accept the specified trigger and transition to the destination state, calculated
 /// dynamically by the supplied function.
 /// </summary>
 /// <param name="trigger">The accepted trigger.</param>
 /// <param name="destinationStateSelector">Function to calculate the state
 /// that the trigger will cause a transition to.</param>
 /// <param name="guard">Function that must return true in order for the
 /// trigger to be accepted.</param>
 /// <returns>The reciever.</returns>
 public StateConfiguration PermitDynamicIf(TTrigger trigger, Func <TState> destinationStateSelector, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(destinationStateSelector, "destinationStateSelector");
     return(InternalPermitDynamicIf(trigger, args => destinationStateSelector(), guard));
 }
コード例 #3
0
 /// <summary>
 /// Specify an action that will execute when transitioning from
 /// the configured state.
 /// </summary>
 /// <param name="exitAction">Action to execute, providing details of the transition.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnExit(Action <Transition> exitAction)
 {
     Enforce.ArgumentNotNull(exitAction, "exitAction");
     m_representation.AddExitAction(exitAction);
     return(this);
 }
コード例 #4
0
 /// <summary>
 /// Specify an action that will execute when transitioning from
 /// the configured state.
 /// </summary>
 /// <param name="exitAction">Action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnExit(Action exitAction)
 {
     Enforce.ArgumentNotNull(exitAction, "exitAction");
     return(OnExit(t => exitAction()));
 }
コード例 #5
0
 /// <summary>
 /// Specify an action that will execute when transitioning into
 /// the configured state.
 /// </summary>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 /// <typeparam name="TArg1">Type of the second trigger argument.</typeparam>
 /// <typeparam name="TArg2">Type of the third trigger argument.</typeparam>
 /// <param name="entryAction">Action to execute, providing details of the transition.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom <TArg0, TArg1, TArg2>(TriggerWithParameters <TArg0, TArg1, TArg2> trigger, Action <TArg0, TArg1, TArg2> entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntryFrom <TArg0, TArg1, TArg2>(trigger, (a0, a1, a2, t) => entryAction(a0, a1, a2)));
 }
コード例 #6
0
 /// <summary>
 /// Specify an action that will execute when transitioning into
 /// the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute, providing details of the transition.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom(TTrigger trigger, Action <Transition> entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     m_representation.AddEntryAction(trigger, (t, args) => entryAction(t));
     return(this);
 }
コード例 #7
0
 internal StateConfiguration(StateRepresentation representation, Func <TState, StateRepresentation> lookup)
 {
     m_representation = Enforce.ArgumentNotNull(representation, "representation");
     m_lookup         = Enforce.ArgumentNotNull(lookup, "lookup");
 }
コード例 #8
0
 /// <summary>
 /// Transition from the current state via the specified trigger.
 /// The target state is determined by the configuration of the current state.
 /// Actions associated with leaving the current state and entering the new one
 /// will be invoked.
 /// </summary>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 /// <typeparam name="TArg1">Type of the second trigger argument.</typeparam>
 /// <typeparam name="TArg2">Type of the third trigger argument.</typeparam>
 /// <param name="arg0">The first argument.</param>
 /// <param name="arg1">The second argument.</param>
 /// <param name="arg2">The third argument.</param>
 /// <param name="trigger">The trigger to fire.</param>
 /// <exception cref="System.InvalidOperationException">The current state does
 /// not allow the trigger to be fired.</exception>
 public void Fire <TArg0, TArg1, TArg2>(TriggerWithParameters <TArg0, TArg1, TArg2> trigger, TArg0 arg0, TArg1 arg1, TArg2 arg2)
 {
     Enforce.ArgumentNotNull(trigger, "trigger");
     InternalFire(trigger.Trigger, arg0, arg1, arg2);
 }
コード例 #9
0
 /// <summary>
 /// Specify an action that will execute when transitioning into
 /// the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntry(Action entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntry(t => entryAction()));
 }
コード例 #10
0
 public DynamicTriggerBehaviour(TTrigger trigger, Func <object[], TState> destination, Func <bool> guard)
     : base(trigger, guard)
 {
     m_destination = Enforce.ArgumentNotNull(destination, "destination");
 }
コード例 #11
0
 public void AddExitAction(Action <Transition> action)
 {
     m_exitActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }
コード例 #12
0
 public void AddEntryAction(Action <Transition, object[]> action)
 {
     m_entryActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }
コード例 #13
0
 public void AddSubstate(StateRepresentation substate)
 {
     Enforce.ArgumentNotNull(substate, "substate");
     m_substates.Add(substate);
 }
コード例 #14
0
 /// <summary>
 /// Construct a state machine with external state storage.
 /// </summary>
 /// <param name="stateAccessor">A function that will be called to read the current state value.</param>
 /// <param name="stateMutator">An action that will be called to write new state values.</param>
 public StateMachine(Func <TState> stateAccessor, Action <TState> stateMutator)
 {
     m_stateAccessor = Enforce.ArgumentNotNull(stateAccessor, "stateAccessor");
     m_stateMutator  = Enforce.ArgumentNotNull(stateMutator, "stateMutator");
 }
コード例 #15
0
 StateConfiguration InternalPermitIf(TTrigger trigger, TState destinationState, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(guard, "guard");
     m_representation.AddTriggerBehaviour(new TransitioningTriggerBehaviour(trigger, destinationState, guard));
     return(this);
 }
コード例 #16
0
 /// <summary>
 /// Specify an action that will execute when transitioning into
 /// the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom(TTrigger trigger, Action entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntryFrom(trigger, t => entryAction()));
 }
コード例 #17
0
 /// <summary>
 /// Ignore the specified trigger when in the configured state, if the guard
 /// returns true..
 /// </summary>
 /// <param name="trigger">The trigger to ignore.</param>
 /// <param name="guard">Function that must return true in order for the
 /// trigger to be ignored.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration IgnoreIf(TTrigger trigger, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(guard, "guard");
     m_representation.AddTriggerBehaviour(new IgnoredTriggerBehaviour(trigger, guard));
     return(this);
 }
コード例 #18
0
            /// <summary>
            /// Ensure that the supplied arguments are compatible with those configured for this
            /// trigger.
            /// </summary>
            /// <param name="args"></param>
            public void ValidateParameters(object[] args)
            {
                Enforce.ArgumentNotNull(args, "args");

                ParameterConversion.Validate(args, m_argumentTypes);
            }