コード例 #1
0
        /// <summary>
        /// Includes the specified actions.
        /// </summary>
        /// <param name="actions">The actions.</param>
        public virtual void Include(params string[] actions)
        {
            if (ExcludedActions.Any())
            {
                throw new InvalidOperationException(ExceptionMessages.ExcludeAlreadyExists);
            }

            Copy(actions, IncludedActions);
        }
コード例 #2
0
        /// <summary>
        /// Determines whether this instance [can respond to action] the specified action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <returns>
        ///     <c>true</c> if this instance [can respond to action] the specified action; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool CanRespondToAction([NotNull] string action)
        {
            // If Nothing is specified then include all.
            if (!IncludedActions.Any() && !ExcludedActions.Any())
            {
                return(true);
            }

            // If includes exist but not excludes then check whether  the specified action exists in includes
            if (IncludedActions.Any() && !ExcludedActions.Any())
            {
                return(IncludedActions.Contains(action, StringComparer.OrdinalIgnoreCase));
            }

            // If includes does not exist but excludes exist then check whether the specified action does not exists in excludes
            if (!IncludedActions.Any() && ExcludedActions.Any())
            {
                return(!ExcludedActions.Contains(action, StringComparer.OrdinalIgnoreCase));
            }

            // Very unusual that we reached here, perhaps the Include/Exclude methods has been overridden.
            return(false);
        }