Esempio n. 1
0
 public void AddEventHandler(object target, Delegate handler)
 {
     if (this.cached_add_event == null)
     {
         MethodInfo addMethod = this.GetAddMethod();
         if (addMethod == null)
         {
             throw new InvalidOperationException("Cannot add a handler to an event that doesn't have a visible add method");
         }
         if (addMethod.DeclaringType.IsValueType)
         {
             if (target == null && !addMethod.IsStatic)
             {
                 throw new TargetException("Cannot add a handler to a non static event with a null target");
             }
             addMethod.Invoke(target, new object[]
             {
                 handler
             });
             return;
         }
         else
         {
             this.cached_add_event = EventInfo.CreateAddEventDelegate(addMethod);
         }
     }
     this.cached_add_event(target, handler);
 }