コード例 #1
0
ファイル: RouteManager.cs プロジェクト: zhangzhouzhe/CQRS
        /// <summary>
        /// Checks if the provided <paramref name="messageType"/> implements <see cref="ICommand{TAuthenticationToken}"/>.
        /// </summary>
        /// <param name="messageType">The <see cref="Type"/> of object to check.</param>
        /// <returns>true if <paramref name="messageType"/> implements <see cref="ICommand{TAuthenticationToken}"/>.</returns>
        protected virtual bool IsACommand(Type messageType)
        {
            bool isACommand = false;
            Type messageCommandInterface = messageType.GetInterfaces().FirstOrDefault(type => type.FullName.StartsWith(CommandType.FullName));

            if (messageCommandInterface != null)
            {
                Type[] genericArguments = messageCommandInterface.GetGenericArguments();
                if (genericArguments.Length == 1)
                {
                    isACommand = CommandType.MakeGenericType(genericArguments.Single()).IsAssignableFrom(messageType);
                }
            }

            return(isACommand);
        }