projects/Extant/Extensions/TypeExtensions.cs
/// <summary>
/// Unsubscribes all Delegates referencing -obj- in static -type-'s list of static events.
/// </summary>
Unsubscribes all Delegates referencing -obj- in static -type-'s list of static events.
Unsubscribes all Delegates referencing - obj - in static - type - ' s list of static events .
public static void ClearAllStaticEventReferencesTo(this Type type, object obj)
        {
            foreach (EventInfo eventInfo in type.GetEvents(BindingFlags.Static | BindingFlags.Public))
            {
                FieldInfo fieldInfo = type.GetField(eventInfo.Name, BindingFlags.Static | BindingFlags.NonPublic);
                MulticastDelegate eventValue = (MulticastDelegate)fieldInfo.GetValue(null);
                if (eventValue != null) 
                {
                    Delegate[] delegates = eventValue.GetInvocationList();
                    foreach (Delegate d in delegates)
                    {
                        if (d.Target == obj)
                        {
                            eventInfo.RemoveEventHandler(null, d);
                        }
                    }
                }
            }
        }
public static void ClearAllStaticEventReferencesTo ( this Type type , object obj ) { foreach ( EventInfo eventInfo in type . GetEvents ( BindingFlags . Static | BindingFlags . Public ) ) { FieldInfo fieldInfo = type . GetField ( eventInfo . Name , BindingFlags . Static | BindingFlags . NonPublic ) ; MulticastDelegate eventValue = ( MulticastDelegate ) fieldInfo . GetValue ( null ) ; if ( eventValue != null ) { Delegate [ ] delegates = eventValue . GetInvocationList ( ) ; foreach ( Delegate d in delegates ) { if ( d . Target == obj ) { eventInfo . RemoveEventHandler ( null , d ) ; } } } } }
Unsubscribes all Delegates referencing -obj- in static -type-'s list of static events.
Unsubscribes all Delegates referencing - obj - in static - type - ' s list of static events .
// will be null if no subscribed event consumers
Type
this
obj
object