/// <summary> /// Creates a new <see cref="RoutedEventClassHandlerManager"/> for the specified event and type, /// populating the manager with relevant handlers from existing types that have already been registered. /// </summary> /// <param name="routedEvent">The event for which to create a class handler manager.</param> /// <param name="classType">The type for which to create a class handler manager.</param> /// <returns>The <see cref="RoutedEventClassHandlerManager"/> that was created for the specified event and type.</returns> private static RoutedEventClassHandlerManager CreateClassHandlerManager(RoutedEvent routedEvent, Type classType) { var manager = new RoutedEventClassHandlerManager(routedEvent, classType); Dictionary <Type, RoutedEventClassHandlerManager> existing; if (managers.TryGetValue(routedEvent, out existing)) { manager.SuspendSort(); foreach (var kvp in existing) { if (classType.IsSubclassOf(kvp.Key)) { var handlers = kvp.Value.GetClassHandlers(); if (handlers == null) { continue; } lock (handlers) { foreach (var handler in handlers) { manager.AddHandler(kvp.Key, handler.Handler, handler.HandledEventsToo); } } } } manager.ResumeSort(); } return(manager); }
/// <summary> /// Creates a new <see cref="RoutedEventClassHandlerManager"/> for the specified event and type, /// populating the manager with relevant handlers from existing types that have already been registered. /// </summary> /// <param name="routedEvent">The event for which to create a class handler manager.</param> /// <param name="classType">The type for which to create a class handler manager.</param> /// <returns>The <see cref="RoutedEventClassHandlerManager"/> that was created for the specified event and type.</returns> private static RoutedEventClassHandlerManager CreateClassHandlerManager(RoutedEvent routedEvent, Type classType) { var manager = new RoutedEventClassHandlerManager(routedEvent, classType); Dictionary<Type, RoutedEventClassHandlerManager> existing; if (managers.TryGetValue(routedEvent, out existing)) { manager.SuspendSort(); foreach (var kvp in existing) { if (classType.IsSubclassOf(kvp.Key)) { var handlers = kvp.Value.GetClassHandlers(); if (handlers == null) continue; lock (handlers) { foreach (var handler in handlers) { manager.AddHandler(kvp.Key, handler.Handler, handler.HandledEventsToo); } } } } manager.ResumeSort(); } return manager; }