internal EventDescriptorCollection FilterEvents(object component, Attribute[] attributes, EventDescriptorCollection events) {
EventDescriptorCollection filteredEvents = events;
if (component is IComponent) {
ITypeDescriptorFilterService tf = (ITypeDescriptorFilterService)GetService(component, typeof(ITypeDescriptorFilterService));
if (tf != null) {
Hashtable filterTable = new Hashtable(events.Count);
if (events != null) {
foreach (EventDescriptor ev in events) {
filterTable[ev.Name] = ev;
}
}
bool cache = tf.FilterEvents((IComponent)component, filterTable);
EventDescriptor[] temp = new EventDescriptor[filterTable.Values.Count];
filterTable.Values.CopyTo(temp, 0);
filteredEvents = new EventDescriptorCollection(temp, true);
}
}
if (attributes != null && attributes.Length > 0) {
ArrayList list = new ArrayList(filteredEvents);
FilterMembers(typeof(EventDescriptor), list, attributes);
EventDescriptor[] temp = new EventDescriptor[list.Count];
list.CopyTo(temp, 0);
filteredEvents = new EventDescriptorCollection(temp, true);
}
return filteredEvents;
}