private void ReflectGetEvents(Type classToReflect) {
Type currentType = classToReflect;
Hashtable eventHash = null;
EventDescriptorCollection baseTypeEvents = null;
// We only want to reflect on one level at a time,
// so if we have a base class above object, we get the
// properties for that first.
//
Type baseType = classToReflect.BaseType;
if (baseType != typeof(object) && baseType != null) {
baseTypeEvents = DebugTypeDescriptor.GetEvents(baseType);
}
// for this particular type, we get _only_ the properties
// declared on that type
//
EventInfo[] events = classToReflect.GetEvents(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
// if we have properties from the base type, stick them into
// a hashtable because we'll want to override them with re-declared
// properties on this particular type.
//
if (baseTypeEvents != null && baseTypeEvents.Count > 0) {
eventHash = new Hashtable();
foreach(EventDescriptor ed in baseTypeEvents) {
eventHash[ed.Name] = ed;
}
}
// now walk each event we got an make sure it's got an add and a remove
//
foreach(EventInfo eventInfo in events) {
if ((!(eventInfo.DeclaringType.IsPublic || eventInfo.DeclaringType.IsNestedPublic)) && (eventInfo.DeclaringType.Assembly == typeof(DebugTypeDescriptor).Assembly)) {
continue;
}
MethodInfo addMethod = eventInfo.GetAddMethod();
MethodInfo removeMethod = eventInfo.GetRemoveMethod();
bool allGood = addMethod != null && removeMethod != null;
// if we have a base list, push the new descriptor
// into the hashtable, otherwise just add it directly.
//
if (eventHash != null) {
EventInfo currentEvent = eventInfo;
// okay, we have to get tricky here...
// if we got an event without an add and remove...which means one is defined on a base class
//
if (!allGood) {
if (eventHash.Contains(eventInfo.Name)) {
// a base class has a property for this,
// so we should just pick up it's
// getter.
//
EventDescriptor basePd = (EventDescriptor)eventHash[eventInfo.Name];
Type declaringType = basePd.ComponentType;
if (declaringType != null) {
EventInfo baseEvent = declaringType.GetEvent(eventInfo.Name);
if (baseEvent != null && baseEvent.GetAddMethod() != null && baseEvent.GetRemoveMethod() != null) {
currentEvent = baseEvent;
}
}
}
}
// push the new info into the hash table.
//
eventHash[eventInfo.Name] = new DebugReflectEventDescriptor(classToReflect, currentEvent);
}
else {
AddMember(new DebugReflectEventDescriptor(classToReflect, eventInfo));
}
}
// now all the things in the hashtable are our "actual" list
// of events, so just set it directly.
//
if (eventHash != null) {
this.memberHash = eventHash;
}
}