diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2009-08-08 03:39:30 +0400 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2009-08-08 03:39:30 +0400 |
commit | 8aba75ce1f0d5167892519f93ac6fb20477d101f (patch) | |
tree | 88154f75f128319380bca73300d6427a66157cb0 /mcs | |
parent | b26affd3c9e2a154133156f69bca052eea06541a (diff) |
2009-08-07 Rodrigo Kumpera <rkumpera@novell.com>
* MonoGenericClass.cs: Implement almost all methods required
to move to inherit from System.Type. The only missing methods
are Is(Array|Pointer|ByRef)Impl and GetElementType since the
runtime still generates weird instances for generics instances
of non-SRE types with SRE types as generic arguments.
2009-08-07 Rodrigo Kumpera <rkumpera@novell.com>
* MonoGenericClassTest.cs: Test for methods that must
throw.
svn path=/trunk/mcs/; revision=139596
Diffstat (limited to 'mcs')
4 files changed, 203 insertions, 2 deletions
diff --git a/mcs/class/corlib/System.Reflection/ChangeLog b/mcs/class/corlib/System.Reflection/ChangeLog index 980ecd3dc96..d37de721bf1 100644 --- a/mcs/class/corlib/System.Reflection/ChangeLog +++ b/mcs/class/corlib/System.Reflection/ChangeLog @@ -1,3 +1,11 @@ +2009-08-07 Rodrigo Kumpera <rkumpera@novell.com> + + * MonoGenericClass.cs: Implement almost all methods required + to move to inherit from System.Type. The only missing methods + are Is(Array|Pointer|ByRef)Impl and GetElementType since the + runtime still generates weird instances for generics instances + of non-SRE types with SRE types as generic arguments. + 2009-08-06 Rodrigo Kumpera <rkumpera@novell.com> * MonoGenericClass.cs (InflateType): Add support to inflate diff --git a/mcs/class/corlib/System.Reflection/MonoGenericClass.cs b/mcs/class/corlib/System.Reflection/MonoGenericClass.cs index 4eb43c9fff5..b9e1ef228f0 100644 --- a/mcs/class/corlib/System.Reflection/MonoGenericClass.cs +++ b/mcs/class/corlib/System.Reflection/MonoGenericClass.cs @@ -710,6 +710,11 @@ namespace System.Reflection return new PointerType (this); } + /*public override Type GetElementType () + { + throw new NotSupportedException (); + }*/ + protected override bool IsCOMObjectImpl () { return false; @@ -719,6 +724,105 @@ namespace System.Reflection { return false; } + + /* + protected override bool IsArrayImpl () + { + return false; + } + + protected override bool IsByRefImpl () + { + return false; + } + + protected override bool IsPointerImpl () + { + return false; + }*/ + + protected override TypeAttributes GetAttributeFlagsImpl () + { + return generic_type.Attributes; + } + + //stuff that throws + public override Type GetInterface (string name, bool ignoreCase) + { + throw new NotSupportedException (); + } + + public override EventInfo GetEvent (string name, BindingFlags bindingAttr) + { + if (!generic_type.IsCompilerContext) + throw new NotSupportedException (); + foreach (var evt in GetEvents (bindingAttr)) { + if (evt.Name == name) + return evt; + } + return null; + } + + public override FieldInfo GetField( string name, BindingFlags bindingAttr) + { + throw new NotSupportedException (); + } + + public override MemberInfo[] GetMembers (BindingFlags bindingAttr) + { + throw new NotSupportedException (); + } + + public override Type GetNestedType (string name, BindingFlags bindingAttr) + { + throw new NotSupportedException (); + } + + public override object InvokeMember (string name, BindingFlags invokeAttr, + Binder binder, object target, object[] args, + ParameterModifier[] modifiers, + CultureInfo culture, string[] namedParameters) + { + throw new NotSupportedException (); + } + + protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, + CallingConventions callConvention, Type[] types, + ParameterModifier[] modifiers) + { + throw new NotSupportedException (); + } + + protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, + Type returnType, Type[] types, ParameterModifier[] modifiers) + { + throw new NotSupportedException (); + } + + protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, + Binder binder, + CallingConventions callConvention, + Type[] types, + ParameterModifier[] modifiers) + { + throw new NotSupportedException (); + } + + //MemberInfo + 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 (); + } } } diff --git a/mcs/class/corlib/Test/System.Reflection/ChangeLog b/mcs/class/corlib/Test/System.Reflection/ChangeLog index 2cd097e8855..03b789c8e43 100644 --- a/mcs/class/corlib/Test/System.Reflection/ChangeLog +++ b/mcs/class/corlib/Test/System.Reflection/ChangeLog @@ -1,3 +1,8 @@ +2009-08-07 Rodrigo Kumpera <rkumpera@novell.com> + + * MonoGenericClassTest.cs: Test for methods that must + throw. + 2009-08-04 Rodrigo Kumpera <rkumpera@novell.com> * MonoGenericClassTest.cs: New file. diff --git a/mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs b/mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs index a5fef620d42..9babc603222 100644 --- a/mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs +++ b/mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs @@ -39,14 +39,19 @@ namespace MonoTests.System.Reflection.Emit } [SetUp] - protected void SetUp () + public void SetUp () + { + SetUp (AssemblyBuilderAccess.RunAndSave); + } + + void SetUp (AssemblyBuilderAccess access) { AssemblyName assemblyName = new AssemblyName (); assemblyName.Name = ASSEMBLY_NAME; assembly = Thread.GetDomain ().DefineDynamicAssembly ( - assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ()); + assemblyName, access, Path.GetTempPath ()); module = assembly.DefineDynamicModule ("module1"); typeCount = 0; @@ -67,6 +72,85 @@ namespace MonoTests.System.Reflection.Emit Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MonoTests.System.Reflection.Emit.MonoGenericClassTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", inst.AssemblyQualifiedName, "#4"); Assert.AreEqual ("foo.type[System.Double,System.String]", inst.ToString (), "#5"); } + + [Test] + [Category ("NotDotNet")] + public void GetEventMustWorkUnderCompilerContext () + { + SetUp (AssemblyBuilderAccess.RunAndSave | (AssemblyBuilderAccess)0x800); + var tb = module.DefineType ("foo.type"); + tb.DefineGenericParameters ("T"); + + var ginst = tb.MakeGenericType (typeof (double)); + + try { + ginst.GetEvent ("foo", BindingFlags.Public | BindingFlags.Instance); + } catch (NotSupportedException) { + Assert.Fail ("#1"); + } + } + + [Test] + public void MethodsThatRaiseNotSupported () + { + var tb = module.DefineType ("foo.type"); + tb.DefineGenericParameters ("T"); + + var ginst = tb.MakeGenericType (typeof (double)); + + /*try { //FIXME this doesn't work yet + ginst.GetElementType (); + Assert.Fail ("#1"); + } catch (NotSupportedException) { }*/ + try { + ginst.GetInterface ("foo", true); + Assert.Fail ("#2"); + } catch (NotSupportedException) { } + try { + ginst.GetEvent ("foo", BindingFlags.Public | BindingFlags.Instance); + Assert.Fail ("#3"); + } catch (NotSupportedException) { } + try { + ginst.GetField ("foo", BindingFlags.Public | BindingFlags.Instance); + Assert.Fail ("#4"); + } catch (NotSupportedException) { } + try { + ginst.GetMembers (BindingFlags.Public | BindingFlags.Instance); + Assert.Fail ("#5"); + } catch (NotSupportedException) { } + try { + ginst.GetMethod ("Foo"); + Assert.Fail ("#6"); + } catch (NotSupportedException) { } + try { + ginst.GetNestedType ("foo", BindingFlags.Public | BindingFlags.Instance); + Assert.Fail ("#7"); + } catch (NotSupportedException) { } + try { + ginst.GetProperty ("foo"); + Assert.Fail ("#8"); + } catch (NotSupportedException) { } + try { + var x = ginst.TypeInitializer; + Assert.Fail ("#9"); + } catch (NotSupportedException) { } + try { + var x = ginst.InvokeMember ("foo", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, null, null); + Assert.Fail ("#10"); + } catch (NotSupportedException) { } + try { + ginst.IsDefined (typeof (int), true); + Assert.Fail ("#11"); + } catch (NotSupportedException) { } + try { + ginst.GetCustomAttributes (true); + Assert.Fail ("#12"); + } catch (NotSupportedException) { } + try { + ginst.GetCustomAttributes (typeof (int), true); + Assert.Fail ("#13"); + } catch (NotSupportedException) { } + } } #endif } |