本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}