public void AddEventHandler(object target, Delegate handler) { #if NET_2_0 && !MICRO_LIB if (cached_add_event == null) { MethodInfo add = GetAddMethod(); if (add == null) { throw new InvalidOperationException("Cannot add a handler to an event that doesn't have a visible add method"); } if (add.DeclaringType.IsValueType) { if (target == null && !add.IsStatic) { throw new TargetException("Cannot add a handler to a non static event with a null target"); } add.Invoke(target, new object [] { handler }); return; } cached_add_event = CreateAddEventDelegate(add); } //if (target == null && is_instance) // throw new TargetException ("Cannot add a handler to a non static event with a null target"); cached_add_event(target, handler); #else MethodInfo add = GetAddMethod(); if (add == null) { throw new InvalidOperationException("Cannot add a handler to an event that doesn't have a visible add method"); } add.Invoke(target, new object [] { handler }); #endif }
public virtual void AddEventHandler(object target, Delegate handler) { // this optimization cause problems with full AOT // see bug https://bugzilla.xamarin.com/show_bug.cgi?id=3682 #if FULL_AOT_RUNTIME MethodInfo add = GetAddMethod(); if (add == null) { throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod); } if (target == null && !add.IsStatic) { throw new TargetException("Cannot add a handler to a non static event with a null target"); } add.Invoke(target, new object [] { handler }); #else if (cached_add_event == null) { MethodInfo add = GetAddMethod(); if (add == null) { throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod); } if (add.DeclaringType.IsValueType) { if (target == null && !add.IsStatic) { throw new TargetException("Cannot add a handler to a non static event with a null target"); } add.Invoke(target, new object [] { handler }); return; } cached_add_event = CreateAddEventDelegate(add); } //if (target == null && is_instance) // throw new TargetException ("Cannot add a handler to a non static event with a null target"); cached_add_event(target, handler); #endif }