/// <summary> /// Registers a <see cref="RoutedEvent"/> /// with the given parameters /// </summary> /// <remarks> /// <see cref="RoutedEvent.Name"/> must be /// unique within the <see cref="RoutedEvent.OwnerType"/> /// (super class types not considered when talking about /// uniqueness) and cannot be null <para/> /// <see cref="RoutedEvent.HandlerType"/> must be a /// type of delegate and cannot be null <para/> /// <see cref="RoutedEvent.OwnerType"/> must be any /// object type and cannot be null <para/> /// <para/> /// /// NOTE: Caller must be the static constructor of the /// <see cref="RoutedEvent.OwnerType"/> - /// enforced by stack walk /// </remarks> /// <param name="name"> /// <see cref="RoutedEvent.Name"/> /// </param> /// <param name="routingStrategy"> /// <see cref="RoutedEvent.RoutingStrategy"/> /// </param> /// <param name="handlerType"> /// <see cref="RoutedEvent.HandlerType"/> /// </param> /// <param name="ownerType"> /// <see cref="RoutedEvent.OwnerType"/> /// </param> /// <returns> /// The new registered <see cref="RoutedEvent"/> /// </returns> /// <ExternalAPI/> public static RoutedEvent RegisterRoutedEvent( string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { if (name == null) { throw new ArgumentNullException("name"); } if (routingStrategy != RoutingStrategy.Tunnel && routingStrategy != RoutingStrategy.Bubble && routingStrategy != RoutingStrategy.Direct) { throw new System.ComponentModel.InvalidEnumArgumentException("routingStrategy", (int)routingStrategy, typeof(RoutingStrategy)); } if (handlerType == null) { throw new ArgumentNullException("handlerType"); } if (ownerType == null) { throw new ArgumentNullException("ownerType"); } if (GlobalEventManager.GetRoutedEventFromName(name, ownerType, false) != null) { throw new ArgumentException(SR.Get(SRID.DuplicateEventName, name, ownerType)); } return(GlobalEventManager.RegisterRoutedEvent(name, routingStrategy, handlerType, ownerType)); }
internal static RoutedEvent GetRoutedEventFromName(string name, Type ownerType) { if (name == null) { throw new ArgumentNullException("name"); } if (ownerType == null) { throw new ArgumentNullException("ownerType"); } return(GlobalEventManager.GetRoutedEventFromName(name, ownerType, true)); }