当前位置: 首页>>代码示例>>C#>>正文


C# ICommandHandler.GetType方法代码示例

本文整理汇总了C#中ICommandHandler.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ICommandHandler.GetType方法的具体用法?C# ICommandHandler.GetType怎么用?C# ICommandHandler.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICommandHandler的用法示例。


在下文中一共展示了ICommandHandler.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterCommandHandler

        /// <summary>
        /// Registers a handler to be used to process commands.
        /// </summary>
        public void RegisterCommandHandler(ICommandHandler commandHandler)
        {
            if (commandHandler == null) throw new ArgumentNullException("commandHandler");

            if (registeredHandlers.Any(h => h.GetType() == commandHandler.GetType()))
                throw new InvalidOperationException("Handler type " + commandHandler.GetType() + " already registered.");

            registeredHandlers.Add(commandHandler);
        }
开发者ID:dineshkummarc,项目名称:Time-Log,代码行数:12,代码来源:CommandProcessor.cs

示例2: Register

        public void Register(ICommandHandler handler)
        {
            if (handler == null) throw new ArgumentNullException(nameof(handler));

            var supportedCommandTypes = handler.GetType()
                .GetInterfaces()
                .Where(iface => iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(ICommandHandler<>))
                .Select(iface => iface.GetGenericArguments()[0])
                .ToList();
            var registeredType = _handlers.Keys.FirstOrDefault(x => supportedCommandTypes.Contains(x));

            if (registeredType != null)
            {
                var commands = String.Join(", ", supportedCommandTypes.Select(x => x.FullName));
                var registeredHandler = _handlers[registeredType];
                var message = $"The command(s) ('{commands}') handled by the received handler ('{handler}') already has a registered handler ('{registeredHandler}').";

                Logging.Darjeel.TraceError(message);
                throw new ArgumentException(message);
            }

            foreach (var commandType in supportedCommandTypes)
            {
                _handlers.Add(commandType, handler);
            }
        }
开发者ID:fvilers,项目名称:Darjeel,代码行数:26,代码来源:CommandHandlerRegistry.cs

示例3: RegisterCommandHandler

        private void RegisterCommandHandler(Type commandType, ICommandHandler commandHandler)
        {
            if (_commandHandlerDict.TryAdd(commandType, commandHandler)) return;

            if (_commandHandlerDict.ContainsKey(commandType))
            {
                throw new DuplicatedCommandHandlerException(commandType, commandHandler.GetInnerCommandHandler().GetType());
            }
            throw new ENodeException("Error occurred when registering {0} for {1} command.", commandHandler.GetType().Name, commandType.Name);
        }
开发者ID:key-value,项目名称:enode,代码行数:10,代码来源:DefaultCommandHandlerProvider.cs

示例4: Register

        /// <summary>
        /// Registers the specified command handler.
        /// </summary>
        public void Register(ICommandHandler commandHandler)
        {
            var genericHandler = typeof(ICommandHandler<>);
            var supportedCommandTypes = commandHandler.GetType()
                .GetInterfaces()
                .Where(iface => iface.IsGenericType && iface.GetGenericTypeDefinition() == genericHandler)
                .Select(iface => iface.GetGenericArguments()[0])
                .ToList();

            if (handlers.Keys.Any(registeredType => supportedCommandTypes.Contains(registeredType)))
                throw new ArgumentException("The command handled by the received handler already has a registered handler.");

            // Register this handler for each of he handled types.
            foreach (var commandType in supportedCommandTypes)
            {
                this.handlers.Add(commandType, commandHandler);
            }
        }
开发者ID:AlexShkorParalect,项目名称:cqrs-journey-code,代码行数:21,代码来源:CommandProcessor.cs

示例5: GetExecutorInfo

 private Executor GetExecutorInfo(ICommand command, ICommandHandler handler)
 {
     var commandHandlerName = string.Format("{0}+{1}", command.GetType().FullName, handler.GetType().FullName);
     return Executors.GetOrAdd(commandHandlerName, CreateExecutor(command, handler));
 }
开发者ID:DerAlbertCom,项目名称:ApereaFramework,代码行数:5,代码来源:CommandExecutor.cs


注:本文中的ICommandHandler.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。