2004-03-23 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Tue, 23 Mar 2004 23:08:19 +0000 (23:08 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 23 Mar 2004 23:08:19 +0000 (23:08 -0000)
* MonoGenericInst.cs: Added support for events.

svn path=/trunk/mcs/; revision=24507

mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MonoGenericInst.cs

index 2d4ba72a5c2893903131981079944444775e6552..5aa4b8ddbf62cf722f174d8be4cf855ea0ab3bd4 100644 (file)
@@ -1,3 +1,7 @@
+2004-03-23  Martin Baulig  <martin@ximian.com>
+
+       * MonoGenericInst.cs: Added support for events.
+
 2004-03-23  Martin Baulig  <martin@ximian.com>
 
        * MonoMethod.cs (MonoMethod.ToString): Don't include the namespace
index 224839f1f048c9b2fd1365203759c573347428a6..1a8a510cb3c734cb98fa07c6ccb4ffa222fba2b9 100644 (file)
@@ -31,7 +31,7 @@ namespace System.Reflection
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties);
+               protected extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                protected extern MethodInfo[] GetMethods_internal (Type reflected_type);
@@ -45,12 +45,23 @@ namespace System.Reflection
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                protected extern PropertyInfo[] GetProperties_internal (Type reflected_type);
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               protected extern EventInfo[] GetEvents_internal (Type reflected_type);
+
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                protected extern Type[] GetNestedTypes_internal ();
 
                private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
 
+               EventInfo[] get_event_info ()
+               {
+                       if (generic_type is TypeBuilder)
+                               return ((TypeBuilder) generic_type).GetEvents_internal (flags);
+                       else
+                               return generic_type.GetEvents (flags);
+               }
+
                void initialize ()
                {
                        if (initialized)
@@ -63,7 +74,8 @@ namespace System.Reflection
                        initialize (generic_type.GetMethods (flags),
                                    generic_type.GetConstructors (flags),
                                    generic_type.GetFields (flags),
-                                   generic_type.GetProperties (flags));
+                                   generic_type.GetProperties (flags),
+                                   get_event_info ());
 
                        initialized = true;
                }
@@ -382,6 +394,80 @@ namespace System.Reflection
                        return result;
                }
 
+               public override EventInfo[] GetEvents (BindingFlags bf)
+               {
+                       initialize ();
+
+                       ArrayList l = new ArrayList ();
+
+                       Type current_type = this;
+                       do {
+                               MonoGenericInst gi = current_type as MonoGenericInst;
+                               if (gi != null)
+                                       l.AddRange (gi.GetEvents_impl (bf, this));
+                               else if (current_type is TypeBuilder)
+                                       l.AddRange (current_type.GetEvents (bf));
+                               else {
+                                       MonoType mt = (MonoType) current_type;
+                                       l.AddRange (mt.GetEvents (bf));
+                                       break;
+                               }
+
+                               if ((bf & BindingFlags.DeclaredOnly) != 0)
+                                       break;
+                               current_type = current_type.BaseType;
+                       } while (current_type != null);
+
+                       EventInfo[] result = new EventInfo [l.Count];
+                       l.CopyTo (result);
+                       return result;
+               }
+
+               protected EventInfo[] GetEvents_impl (BindingFlags bf, Type reftype)
+               {
+                       ArrayList l = new ArrayList ();
+                       bool match;
+                       MethodAttributes mattrs;
+                       MethodInfo accessor;
+
+                       EventInfo[] events = GetEvents_internal (reftype);
+
+                       for (int i = 0; i < events.Length; i++) {
+                               EventInfo c = events [i];
+
+                               match = false;
+                               accessor = c.GetAddMethod (true);
+                               if (accessor == null)
+                                       accessor = c.GetRemoveMethod (true);
+                               if (accessor == null)
+                                       continue;
+                               mattrs = accessor.Attributes;
+                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
+                                       if ((bf & BindingFlags.Public) != 0)
+                                               match = true;
+                               } else {
+                                       if ((bf & BindingFlags.NonPublic) != 0)
+                                               match = true;
+                               }
+                               if (!match)
+                                       continue;
+                               match = false;
+                               if ((mattrs & MethodAttributes.Static) != 0) {
+                                       if ((bf & BindingFlags.Static) != 0)
+                                               match = true;
+                               } else {
+                                       if ((bf & BindingFlags.Instance) != 0)
+                                               match = true;
+                               }
+                               if (!match)
+                                       continue;
+                               l.Add (c);
+                       }
+                       EventInfo[] result = new EventInfo [l.Count];
+                       l.CopyTo (result);
+                       return result;
+               }
+
                public override Type[] GetNestedTypes (BindingFlags bf)
                {
                        initialize ();