예제 #1
0
 private void registerEventHandlers(IAsyncHandler h)
 {
     MethodInfo[] methods = h.GetType().GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     foreach (MethodInfo method in methods)
     {
         var attrs = method.GetCustomAttributes <EventListenerAttribute>();
         foreach (var attr in attrs)
         {
             AddEventListener(attr.Pattern, (EventHandler)method.CreateDelegate(typeof(EventHandler), h));
         }
     }
 }
예제 #2
0
 private static TAttribute GetHandlerAttribute <TAttribute>(IAsyncHandler h) where TAttribute : Attribute
 {
     if (h != null)
     {
         var attr = h.GetType().GetTypeInfo().GetCustomAttribute <TAttribute>();
         if (attr is TAttribute)
         {
             return(attr);
         }
     }
     return(null);
 }