/// <summary> /// This method does filtering based on eventInfo, and should only be used when the TargetFrameworkProvider /// is not directly available, for example in the CBM case where it is in another appdomain. /// </summary> private static EventDescriptorCollection GetFilteredEventDescriptorCollection(Type objectType, object instance) { Debug.Assert(s_cbmTdpBridge != null, "s_cbmTdpBridge should not be null"); EventDescriptorCollection eventDescriptors = null; if (instance != null) { eventDescriptors = TypeDescriptor.GetEvents(instance); } else if (objectType != null) { eventDescriptors = TypeDescriptor.GetEvents(objectType); } else { throw new ArgumentException("At least one argument should be non-null"); } BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; Type typeToUse = GetTypeToUseForCBMBridge(objectType); string[] eventNames = s_cbmTdpBridge.GetFilteredEvents(typeToUse, bindingFlags); var filteredEventDescriptors = from e in eventNames let d = eventDescriptors[e] where d != null select d; return(new EventDescriptorCollection(filteredEventDescriptors.ToArray())); }
private static EventDescriptorCollection GetFilteredEventDescriptorCollection(Type objectType, object instance) { EventDescriptorCollection eventDescriptors = null; if (instance != null) { eventDescriptors = TypeDescriptor.GetEvents(instance); } else { if (objectType == null) { throw new ArgumentException("At least one argument should be non-null"); } eventDescriptors = TypeDescriptor.GetEvents(objectType); } BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; Type typeToUseForCBMBridge = GetTypeToUseForCBMBridge(objectType); return(new EventDescriptorCollection((from e in s_cbmTdpBridge.GetFilteredEvents(typeToUseForCBMBridge, bindingFlags) let d = eventDescriptors[e] where d != null select d).ToArray <EventDescriptor>())); }