本文整理汇总了C#中IEventHandler.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IEventHandler.GetType方法的具体用法?C# IEventHandler.GetType怎么用?C# IEventHandler.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEventHandler
的用法示例。
在下文中一共展示了IEventHandler.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildHandlerInvocations
private IEnumerable<Tuple<Type, Action<IEvent>>> BuildHandlerInvocations(IEventHandler handler)
{
return handler.GetType().GetInterfaces()
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEventHandler<>))
.Select(i => new { HandlerInterface = i, EventType = i.GetGenericArguments()[0] })
.Select(e => new Tuple<Type, Action<IEvent>>(e.EventType, this.BuildHandlerInvocation(handler, e.HandlerInterface, e.EventType)));
}
示例2: TryInvoke
private static bool TryInvoke(IEventHandler eventHandler, string interfaceName, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
Type type = eventHandler.GetType();
foreach (var interfaceType in type.GetInterfaces()) {
if (String.Equals(interfaceType.Name, interfaceName, StringComparison.OrdinalIgnoreCase)) {
return TryInvokeMethod(eventHandler, interfaceType, methodName, arguments, out returnValue);
}
}
returnValue = null;
return false;
}
示例3: TryInvokeMethod
private static bool TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, string messageName, string interfaceName, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
var key = eventHandler.GetType().FullName + "_" + messageName + "_" + String.Join("_", arguments.Keys);
var cachedDelegate = _delegateCache.GetOrAdd(key, k => {
var method = GetMatchingMethod(eventHandler, interfaceType, methodName, arguments);
return method != null
? Tuple.Create(method.GetParameters(), DelegateHelper.CreateDelegate<IEventHandler>(eventHandler.GetType(), method))
: null;
});
if (cachedDelegate != null) {
var args = cachedDelegate.Item1.Select(methodParameter => arguments[methodParameter.Name]).ToArray();
var result = cachedDelegate.Item2(eventHandler, args);
returnValue = result as IEnumerable;
if (result != null && (returnValue == null || result is string))
returnValue = new[] { result };
return true;
}
returnValue = null;
return false;
}
示例4: _HandleEvent
private static void _HandleEvent(IEventHandler handler,IEvent evnt,ref Thread delThread)
{
delThread = Thread.CurrentThread;
if (delThread.Name == null)
{
lock (_rand)
{
Thread.CurrentThread.Name = "EventHandlerCall{" + handler.GetType().FullName + "}[" + _rand.Next().ToString() + "]";
}
}
Thread.CurrentThread.IsBackground = true;
handler.ProcessEvent(evnt);
}
示例5: TryInvokeMethod
private static bool TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
MethodInfo method = _interfaceMethodsCache.GetOrAdd(String.Concat(eventHandler.GetType().FullName + "_" + interfaceType.Name, "_", methodName, "_", String.Join("_", arguments.Keys)), GetMatchingMethod(eventHandler, interfaceType, methodName, arguments));
if (method != null) {
var parameters = new List<object>();
foreach (var methodParameter in method.GetParameters()) {
parameters.Add(arguments[methodParameter.Name]);
}
var result = method.Invoke(eventHandler, parameters.ToArray());
returnValue = result as IEnumerable;
if (returnValue == null && result != null)
returnValue = new[] { result };
return true;
}
returnValue = null;
return false;
}
示例6: Register
public void Register(IEventHandler handler)
{
if (handler == null) throw new ArgumentNullException(nameof(handler));
var supportedEventTypes = handler.GetType()
.GetInterfaces()
.Where(iface => iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(IEventHandler<>))
.Select(iface => iface.GetGenericArguments()[0])
.ToList();
foreach (var eventType in supportedEventTypes)
{
List<IEventHandler> entry;
if (!_handlers.TryGetValue(eventType, out entry))
{
entry = new List<IEventHandler>();
_handlers.Add(eventType, entry);
}
_handlers[eventType].Add(handler);
}
}
示例7: TryInvoke
private static bool TryInvoke(IEventHandler eventHandler, string messageName, string interfaceName, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
var matchingInterface = eventHandler.GetType().GetInterface(interfaceName);
return TryInvokeMethod(eventHandler, matchingInterface, messageName, interfaceName, methodName, arguments, out returnValue);
}
示例8: TryInvoke
private static void TryInvoke(IEventHandler eventHandler, string interfaceName, string methodName, IDictionary<string, object> arguments)
{
Type type = eventHandler.GetType();
foreach (var interfaceType in type.GetInterfaces()) {
if (String.Equals(interfaceType.Name, interfaceName, StringComparison.OrdinalIgnoreCase)) {
TryInvokeMethod(eventHandler, interfaceType, methodName, arguments);
break;
}
}
}