Author: gert
Date: 2008-01-16 14:00:34 -0500 (Wed, 16 Jan 2008)
New Revision: 93080
Modified:
trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
Log:
* TypeBuilder.cs (GetConstructorImpl): Use GetConstructor on created
type. Original implementation did not take into account the binding
flags and failed with a NotSupportedException if the default binder
checked if a ParamArrayAttribute was defined. It also does not make
sense to return a ConstructorBuilder once the type is emitted.
(GetConstructors): When the type is emitted, use GetConstructors
on the created type.
(GetFields): Removed duplicate code.
(GetMethodsByName): Fixed matching of methods in the parent class
depending on their accessibility:
- Private: never include private methods of parent
- Public: ignore if Public flag is not set
- Assembly: ignore if NonPublic is not set or when on the 1.0 profile
- Rest (Family, FamANDAssem, FamORAssem): ignore if NonPublic flag is
not set
Static methods of the parent are ignored unless the FlattenHierarchy
flag is set.
(GetProperties): When the type is emitted, use GetProperties on the
created type as the TypeBuilder implementation itself does not include
properties from the parent class.
* TypeBuilderTest.cs: Enabled tests for bug #322762.
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2008-01-16
19:00:19 UTC (rev 93079)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2008-01-16
19:00:34 UTC (rev 93080)
@@ -1,3 +1,26 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * TypeBuilder.cs (GetConstructorImpl): Use GetConstructor on created
+ type. Original implementation did not take into account the binding
+ flags and failed with a NotSupportedException if the default binder
+ checked if a ParamArrayAttribute was defined. It also does not make
+ sense to return a ConstructorBuilder once the type is emitted.
+ (GetConstructors): When the type is emitted, use GetConstructors
+ on the created type.
+ (GetFields): Removed duplicate code.
+ (GetMethodsByName): Fixed matching of methods in the parent class
+ depending on their accessibility:
+ - Private: never include private methods of parent
+ - Public: ignore if Public flag is not set
+ - Assembly: ignore if NonPublic is not set or when on the 1.0 profile
+ - Rest (Family, FamANDAssem, FamORAssem): ignore if NonPublic flag is
+ not set
+ Static methods of the parent are ignored unless the FlattenHierarchy
+ flag is set.
+ (GetProperties): When the type is emitted, use GetProperties on the
+ created type as the TypeBuilder implementation itself does not include
+ properties from the parent class.
+
2007-12-31 Gert Driesen <[EMAIL PROTECTED]>
* AssemblyBuilder.cs (UnprotectedGetName): Set the public key token
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2008-01-16 19:00:19 UTC (rev 93079)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2008-01-16 19:00:34 UTC (rev 93080)
@@ -297,42 +297,9 @@
ParameterModifier[] modifiers)
{
check_created ();
-
- if (ctors == null)
- return null;
- ConstructorBuilder found = null;
- int count = 0;
-
- foreach (ConstructorBuilder cb in ctors) {
- if (callConvention != CallingConventions.Any &&
cb.CallingConvention != callConvention)
- continue;
- found = cb;
- count++;
- }
-
- if (count == 0)
- return null;
- if (types == null) {
- if (count > 1)
- throw new AmbiguousMatchException ();
- return found;
- }
- MethodBase[] match = new MethodBase [count];
- if (count == 1)
- match [0] = found;
- else {
- count = 0;
- foreach (ConstructorInfo m in ctors) {
- if (callConvention !=
CallingConventions.Any && m.CallingConvention != callConvention)
- continue;
- match [count++] = m;
- }
- }
- if (binder == null)
- binder = Binder.DefaultBinder;
- return (ConstructorInfo) binder.SelectMethod
(bindingAttr, match,
- types, modifiers);
+ return created.GetConstructor (bindingAttr, binder,
+ callConvention, types, modifiers);
}
public override bool IsDefined (Type attributeType, bool
inherit)
@@ -809,6 +776,9 @@
#endif
public override ConstructorInfo[] GetConstructors (BindingFlags
bindingAttr)
{
+ if (is_created)
+ return created.GetConstructors (bindingAttr);
+
if (ctors == null)
return new ConstructorInfo [0];
ArrayList l = new ArrayList ();
@@ -964,15 +934,8 @@
public override FieldInfo[] GetFields (BindingFlags bindingAttr)
{
-#if NET_2_0 || BOOTSTRAP_NET_2_0
- // FIXME: In the generic case, this leads to a crash
- // http://bugzilla.ximian.com/show_bug.cgi?id=82625
if (created != null)
return created.GetFields (bindingAttr);
-#else
- if (created != null)
- return created.GetFields (bindingAttr);
-#endif
if (fields == null)
return new FieldInfo [0];
@@ -1044,16 +1007,54 @@
private MethodInfo[] GetMethodsByName (string name,
BindingFlags bindingAttr, bool ignoreCase, Type reflected_type)
{
MethodInfo[] candidates;
+ bool match;
+ MethodAttributes mattrs;
+
if (((bindingAttr & BindingFlags.DeclaredOnly) == 0) &&
(parent != null)) {
- BindingFlags parentBindingAttr = bindingAttr &
(~BindingFlags.Static);
- MethodInfo [] parent_methods =
parent.GetMethods (parentBindingAttr);
- if (methods == null)
- candidates = parent_methods;
- else {
- candidates = new MethodInfo
[methods.Length + parent_methods.Length];
- parent_methods.CopyTo (candidates, 0);
- methods.CopyTo (candidates,
parent_methods.Length);
+ MethodInfo [] parent_methods =
parent.GetMethods (bindingAttr);
+ ArrayList parent_candidates = new ArrayList
(parent_methods.Length);
+
+ bool flatten = (bindingAttr &
BindingFlags.FlattenHierarchy) != 0;
+
+ for (int i = 0; i < parent_methods.Length; i++)
{
+ MethodInfo m = parent_methods [i];
+
+ mattrs = m.Attributes;
+
+ if (m.IsStatic && !flatten)
+ continue;
+
+ switch (mattrs &
MethodAttributes.MemberAccessMask) {
+ case MethodAttributes.Public:
+ match = (bindingAttr &
BindingFlags.Public) != 0;
+ break;
+ case MethodAttributes.Assembly:
+#if NET_2_0
+ match = (bindingAttr &
BindingFlags.NonPublic) != 0;
+#else
+ match = false;
+#endif
+ break;
+ case MethodAttributes.Private:
+ match = false;
+ break;
+ default:
+ match = (bindingAttr &
BindingFlags.NonPublic) != 0;
+ break;
+ }
+
+ if (match)
+ parent_candidates.Add (m);
}
+
+ if (methods == null) {
+ candidates = new MethodInfo
[parent_candidates.Count];
+ parent_candidates.CopyTo (candidates);
+ } else {
+ candidates = new MethodInfo
[methods.Length + parent_candidates.Count];
+ parent_candidates.CopyTo (candidates,
0);
+ methods.CopyTo (candidates,
parent_candidates.Count);
+ }
}
else
candidates = methods;
@@ -1062,8 +1063,6 @@
return new MethodInfo [0];
ArrayList l = new ArrayList ();
- bool match;
- MethodAttributes mattrs;
foreach (MethodInfo c in candidates) {
if (c == null)
@@ -1188,6 +1187,9 @@
public override PropertyInfo[] GetProperties (BindingFlags
bindingAttr)
{
+ if (is_created)
+ return created.GetProperties (bindingAttr);
+
if (properties == null)
return new PropertyInfo [0];
ArrayList l = new ArrayList ();
Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
2008-01-16 19:00:19 UTC (rev 93079)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
2008-01-16 19:00:34 UTC (rev 93080)
@@ -1,3 +1,7 @@
+2008-01-16 Gert Driesen <[EMAIL PROTECTED]>
+
+ * TypeBuilderTest.cs: Enabled tests for bug #322762.
+
2008-01-06 Gert Driesen <[EMAIL PROTECTED]>
* AssemblyBuilderTest.cs: Added (NotWorking) test for bug #351932.
Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
2008-01-16 19:00:19 UTC (rev 93079)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
2008-01-16 19:00:34 UTC (rev 93080)
@@ -1637,7 +1637,6 @@
}
[Test] // GetConstructor (BindingFlags, Binder, Type [],
ParameterModifier [])
- [Category ("NotWorking")] // bug #322762
public void GetConstructor2_Complete ()
{
BindingFlags flags;
@@ -2871,7 +2870,6 @@
}
[Test] // GetConstructors (BindingFlags)
- [Category ("NotWorking")] // bug #322762
public void GetConstructors2_Complete ()
{
BindingFlags flags;
@@ -3297,7 +3295,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetEventsFlagsComplete_Inheritance ()
{
EventInfo [] events;
@@ -3551,7 +3548,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetEventFlagsComplete_Inheritance ()
{
BindingFlags flags;
@@ -4316,7 +4312,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetFieldsFlagsComplete_Inheritance ()
{
FieldInfo [] fields;
@@ -4647,7 +4642,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetFieldFlagsComplete_Inheritance ()
{
BindingFlags flags;
@@ -5337,7 +5331,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetPropertiesFlagsComplete_Inheritance ()
{
PropertyInfo [] props;
@@ -5630,7 +5623,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetMethodFlagsComplete ()
{
BindingFlags flags;
@@ -6418,7 +6410,6 @@
[Test]
[Category ("NotDotNet")] // mcs depends on this
- [Category ("NotWorking")] // bug #322762
public void TestGetMethodsFlagsIncomplete_Inheritance ()
{
MethodInfo [] methods;
@@ -7165,7 +7156,6 @@
}
[Test]
- [Category ("NotWorking")] // bug #322762
public void TestGetMethodsFlagsComplete_Inheritance ()
{
MethodInfo [] methods;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches