+2009-08-03 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * EventBuilder.cs: Make some fields internal.
+
+ * TypeBuilder.cs: Make events field internal.
+ Remove some MonoTODOs that are already done.
+
+ * EventOnTypeBuilderInst.cs: New file which implements
+ the required functionality by compiler context.
+
2009-07-30 Rodrigo Kumpera <rkumpera@novell.com>
* TypeBuilder.cs (IsDefined): Throw if not
[ClassInterface (ClassInterfaceType.None)]
public sealed class EventBuilder : _EventBuilder {
#pragma warning disable 169, 414
- string name;
+ internal string name;
Type type;
TypeBuilder typeb;
CustomAttributeBuilder[] cattrs;
- MethodBuilder add_method;
- MethodBuilder remove_method;
- MethodBuilder raise_method;
- MethodBuilder[] other_methods;
- EventAttributes attrs;
+ internal MethodBuilder add_method;
+ internal MethodBuilder remove_method;
+ internal MethodBuilder raise_method;
+ internal MethodBuilder[] other_methods;
+ internal EventAttributes attrs;
int table_idx;
#pragma warning restore 169, 414
--- /dev/null
+//
+// System.Reflection.Emit/EventOnTypeBuilderInst.cs
+//
+// Author:
+// Rodrigo Kumpera (rkumpera@novell.com)
+//
+//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.Reflection;
+
+#if NET_2_0 || BOOTSTRAP_NET_2_0
+
+namespace System.Reflection.Emit
+{
+ /*
+ * This class represents an event of an instantiation of a generic type builder.
+ */
+ internal class EventOnTypeBuilderInst : EventInfo
+ {
+ MonoGenericClass instantiation;
+ EventBuilder evt;
+
+ internal EventOnTypeBuilderInst (MonoGenericClass instantiation, EventBuilder evt)
+ {
+ this.instantiation = instantiation;
+ this.evt = evt;
+ }
+
+ public override EventAttributes Attributes {
+ get { return evt.attrs; }
+ }
+
+ public override MethodInfo GetAddMethod (bool nonPublic)
+ {
+ if (evt.add_method == null || (!nonPublic && !evt.add_method.IsPublic))
+ return null;
+ return TypeBuilder.GetMethod (instantiation, evt.add_method);
+ }
+
+ public override MethodInfo GetRaiseMethod (bool nonPublic)
+ {
+ if (evt.raise_method == null || (!nonPublic && !evt.raise_method.IsPublic))
+ return null;
+ return TypeBuilder.GetMethod (instantiation, evt.raise_method);
+ }
+
+ public override MethodInfo GetRemoveMethod (bool nonPublic)
+ {
+ if (evt.remove_method == null || (!nonPublic && !evt.remove_method.IsPublic))
+ return null;
+ return TypeBuilder.GetMethod (instantiation, evt.remove_method);
+ }
+
+#if NET_2_0
+ public override MethodInfo[] GetOtherMethods (bool nonPublic)
+ {
+ if (evt.other_methods == null)
+ return new MethodInfo [0];
+
+ ArrayList ar = new ArrayList ();
+ foreach (MethodInfo method in evt.other_methods) {
+ if (nonPublic || method.IsPublic)
+ ar.Add (TypeBuilder.GetMethod (instantiation, method));
+ }
+ MethodInfo[] res = new MethodInfo [ar.Count];
+ ar.CopyTo (res, 0);
+ return res;
+ }
+#endif
+
+ public override Type DeclaringType {
+ get { return instantiation; }
+ }
+
+ public override string Name {
+ get { return evt.name; }
+ }
+
+ public override Type ReflectedType {
+ get { return instantiation; }
+ }
+
+ public override bool IsDefined (Type attributeType, bool inherit)
+ {
+ throw new NotSupportedException ();
+ }
+
+ public override object [] GetCustomAttributes (bool inherit)
+ {
+ throw new NotSupportedException ();
+ }
+
+ public override object [] GetCustomAttributes (Type attributeType, bool inherit)
+ {
+ throw new NotSupportedException ();
+ }
+ }
+}
+
+#endif
\ No newline at end of file
internal PropertyBuilder[] properties;
internal int num_fields;
internal FieldBuilder[] fields;
- private EventBuilder[] events;
+ internal EventBuilder[] events;
private CustomAttributeBuilder[] cattrs;
internal TypeBuilder[] subtypes;
internal TypeAttributes attrs;
return new ArrayType (this, rank);
}
- [MonoTODO]
public override Type MakeByRefType ()
{
return new ByRefType (this);
return base.MakeGenericType (typeArguments);
}
- [MonoTODO]
public override Type MakePointerType ()
{
return new PointerType (this);
+2009-08-03 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * MonoGenericClass.cs (initialize): Remember the number
+ of events available at initialization time. This is required as
+ mcs expect this behavior under compiler context that new events
+ are not returned for an instance that was inflated before.
+
+ * MonoGenericClass.cs: Kill GetEvents_internal and implement it
+ in terms of managed code.
+
2009-07-30 Zoltan Varga <vargaz@gmail.com>
* FieldInfo.cs: Throw an exception if internal_from_handle_type ()
#endregion
Hashtable fields, ctors, methods;
+ int event_count;
internal MonoGenericClass ()
: base (null)
[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern EventInfo[] GetEvents_internal (Type reflected_type);
private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
MonoGenericClass parent = GetParentType () as MonoGenericClass;
if (parent != null)
parent.initialize ();
-
+ EventInfo[] events = generic_type.GetEvents_internal (flags);
+ event_count = events.Length;
+
initialize (generic_type.GetMethods (flags),
generic_type.GetConstructorsInternal (flags),
generic_type.GetFields (flags),
generic_type.GetProperties (flags),
- generic_type.GetEvents_internal (flags));
+ events);
initialized = true;
}
do {
MonoGenericClass gi = current_type as MonoGenericClass;
if (gi != null)
- l.AddRange (gi.GetEvents_impl (bf, this));
+ l.AddRange (gi.GetEventsInternal (bf, this));
else if (current_type is TypeBuilder)
l.AddRange (current_type.GetEvents (bf));
else {
l.CopyTo (result);
return result;
}
+
+ EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
+ if (generic_type.events == null)
+ return new EventInfo [0];
+
+ initialize ();
- protected EventInfo[] GetEvents_impl (BindingFlags bf, Type reftype)
- {
ArrayList l = new ArrayList ();
bool match;
MethodAttributes mattrs;
MethodInfo accessor;
- initialize ();
-
- EventInfo[] events = GetEvents_internal (reftype);
-
- for (int i = 0; i < events.Length; i++) {
- EventInfo c = events [i];
+ for (int i = 0; i < event_count; ++i) {
+ EventBuilder ev = generic_type.events [i];
match = false;
- accessor = c.GetAddMethod (true);
+ accessor = ev.add_method;
if (accessor == null)
- accessor = c.GetRemoveMethod (true);
+ accessor = ev.remove_method;
if (accessor == null)
continue;
mattrs = accessor.Attributes;
}
if (!match)
continue;
- l.Add (c);
+ l.Add (new EventOnTypeBuilderInst (this, ev));
}
EventInfo[] result = new EventInfo [l.Count];
l.CopyTo (result);
System.Reflection.Emit/DynamicMethod.cs
System.Reflection.Emit/EnumBuilder.cs
System.Reflection.Emit/EventBuilder.cs
+System.Reflection.Emit/EventOnTypeBuilderInst.cs
System.Reflection.Emit/EventToken.cs
System.Reflection.Emit/FieldBuilder.cs
System.Reflection.Emit/FieldOnTypeBuilderInst.cs