2009-12-17 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / corlib / Test / System / TypeTest.cs
index a79c722db43ec64ea032f2015ca76dd8ebf8845e..12d86043631f3269906cff44d42e82d5121f8bed 100644 (file)
@@ -9,10 +9,9 @@
 
 using NUnit.Framework;
 using System;
+using System.Threading;
 using System.Collections;
-#if NET_2_0
 using System.Collections.Generic;
-#endif
 using System.IO;
 using System.Reflection;
 using System.Reflection.Emit;
@@ -157,7 +156,6 @@ namespace MonoTests.System
                }
        }
 
-#if NET_2_0
        public class Foo<T>
        {
                public T Whatever;
@@ -183,7 +181,12 @@ namespace MonoTests.System
        public class Baz<T> : IBar<T>
        {
        }
-#endif
+
+       class Gazonk {
+
+               public static void Bang<S> () {}
+       }
+
        public class Bug348522
        {
                public void Test (int __argument)
@@ -254,11 +257,11 @@ namespace MonoTests.System
                private void ByrefMethod (ref int i, ref Derived1 j, ref Base1 k)
                {
                }
-#if NET_2_0
+
                private void GenericMethod<Q> (Q q)
                {
                }
-#endif
+
                [Test]
                public void TestIsAssignableFrom ()
                {
@@ -325,11 +328,9 @@ namespace MonoTests.System
                        Assert.IsTrue (mi.GetParameters ()[1].ParameterType.IsAssignableFrom (mi.GetParameters ()[1].ParameterType));
 
                        // Tests for type parameters
-#if NET_2_0
                        mi = typeof (TypeTest).GetMethod ("GenericMethod", BindingFlags.Instance|BindingFlags.NonPublic);
                        Assert.IsTrue (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (mi.GetParameters ()[0].ParameterType));
                        Assert.IsFalse (mi.GetParameters ()[0].ParameterType.IsAssignableFrom (typeof (int)));
-#endif
                }
 
                [Test]
@@ -407,11 +408,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#A2");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#A3");
                        Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#A4");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#A5");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#A5");
-#endif
                        Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#A6");
                        Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#A7");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#A8");
@@ -431,11 +428,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#A22");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#A23");
                        Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#A24");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#A25");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#A25");
-#endif
                        Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#A26");
                        Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#A27");
                        Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#A28");
@@ -552,11 +545,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#E2");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#E3");
                        Assert.IsFalse (ContainsProperty (props, "PubInstBase"), "#E4");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#E5");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#E5");
-#endif
                        Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#E6");
                        Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#E7");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#E8");
@@ -576,11 +565,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#E22");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#E23");
                        Assert.IsFalse (ContainsProperty (props, "PubInstBlue"), "#E24");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#E25");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#E25");
-#endif
                        Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#E26");
                        Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#E27");
                        Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#E28");
@@ -675,11 +660,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtStatBase"), "#H12");
                        Assert.IsTrue (ContainsProperty (props, "ProIntStatBase"), "#H13");
                        Assert.IsFalse (ContainsProperty (props, "PubStatBase"), "#H14");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntStatBase"), "#H15");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntStatBase"), "#H15");
-#endif
                        Assert.IsTrue (ContainsProperty (props, "PrivStat"), "#H16");
                        Assert.IsTrue (ContainsProperty (props, "ProtStat"), "#H17");
                        Assert.IsTrue (ContainsProperty (props, "ProIntStat"), "#H18");
@@ -694,11 +675,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtStatBlue"), "#H27");
                        Assert.IsTrue (ContainsProperty (props, "ProIntStatBlue"), "#H28");
                        Assert.IsFalse (ContainsProperty (props, "PubStatBlue"), "#H29");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntStatBlue"), "#H30");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntStatBlue"), "#H50");
-#endif
 
                        flags = BindingFlags.Instance | BindingFlags.NonPublic |
                                BindingFlags.DeclaredOnly;
@@ -848,11 +825,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBase"), "#M2");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBase"), "#M3");
                        Assert.IsTrue (ContainsProperty (props, "PubInstBase"), "#M4");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBase"), "#M5");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBase"), "#M5");
-#endif
                        Assert.IsTrue (ContainsProperty (props, "PrivInst"), "#M6");
                        Assert.IsTrue (ContainsProperty (props, "ProtInst"), "#M7");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInst"), "#M8");
@@ -872,11 +845,7 @@ namespace MonoTests.System
                        Assert.IsTrue (ContainsProperty (props, "ProtInstBlue"), "#M22");
                        Assert.IsTrue (ContainsProperty (props, "ProIntInstBlue"), "#M23");
                        Assert.IsTrue (ContainsProperty (props, "PubInstBlue"), "#M24");
-#if NET_2_0
                        Assert.IsTrue (ContainsProperty (props, "IntInstBlue"), "#M25");
-#else
-                       Assert.IsFalse (ContainsProperty (props, "IntInstBlue"), "#M25");
-#endif
                        Assert.IsFalse (ContainsProperty (props, "PrivStatBlue"), "#M26");
                        Assert.IsFalse (ContainsProperty (props, "ProtStatBlue"), "#M27");
                        Assert.IsFalse (ContainsProperty (props, "ProIntStatBlue"), "#M28");
@@ -947,11 +916,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#A2");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#A3");
                        Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#A4");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#A5");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#A5");
-#endif
                        Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#A6");
                        Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#A7");
                        Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#A8");
@@ -971,11 +936,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#A22");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#A23");
                        Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#A24");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#A25");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#A25");
-#endif
                        Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#A26");
                        Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#A27");
                        Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#A28");
@@ -1088,11 +1049,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#E2");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#E3");
                        Assert.IsNull (type.GetProperty ("PubInstBase", flags), "#E4");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#E5");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#E5");
-#endif
                        Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#E6");
                        Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#E7");
                        Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#E8");
@@ -1112,11 +1069,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#E22");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#E23");
                        Assert.IsNull (type.GetProperty ("PubInstBlue", flags), "#E24");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#E25");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#E25");
-#endif
                        Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#E26");
                        Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#E27");
                        Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#E28");
@@ -1208,11 +1161,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtStatBase", flags), "#H12");
                        Assert.IsNotNull (type.GetProperty ("ProIntStatBase", flags), "#H13");
                        Assert.IsNull (type.GetProperty ("PubStatBase", flags), "#H14");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntStatBase", flags), "#H15");
-#else
-                       Assert.IsNull (type.GetProperty ("IntStatBase", flags), "#H15");
-#endif
                        Assert.IsNotNull (type.GetProperty ("PrivStat", flags), "#H16");
                        Assert.IsNotNull (type.GetProperty ("ProtStat", flags), "#H17");
                        Assert.IsNotNull (type.GetProperty ("ProIntStat", flags), "#H18");
@@ -1227,11 +1176,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtStatBlue", flags), "#H27");
                        Assert.IsNotNull (type.GetProperty ("ProIntStatBlue", flags), "#H28");
                        Assert.IsNull (type.GetProperty ("PubStatBlue", flags), "#H29");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntStatBlue", flags), "#H30");
-#else
-                       Assert.IsNull (type.GetProperty ("IntStatBlue", flags), "#H60");
-#endif
 
                        flags = BindingFlags.Instance | BindingFlags.NonPublic |
                                BindingFlags.DeclaredOnly;
@@ -1376,11 +1321,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBase", flags), "#M2");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBase", flags), "#M3");
                        Assert.IsNotNull (type.GetProperty ("PubInstBase", flags), "#M4");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBase", flags), "#M5");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBase", flags), "#M5");
-#endif
                        Assert.IsNotNull (type.GetProperty ("PrivInst", flags), "#M6");
                        Assert.IsNotNull (type.GetProperty ("ProtInst", flags), "#M7");
                        Assert.IsNotNull (type.GetProperty ("ProIntInst", flags), "#M8");
@@ -1400,11 +1341,7 @@ namespace MonoTests.System
                        Assert.IsNotNull (type.GetProperty ("ProtInstBlue", flags), "#M22");
                        Assert.IsNotNull (type.GetProperty ("ProIntInstBlue", flags), "#M23");
                        Assert.IsNotNull (type.GetProperty ("PubInstBlue", flags), "#M24");
-#if NET_2_0
                        Assert.IsNotNull (type.GetProperty ("IntInstBlue", flags), "#M25");
-#else
-                       Assert.IsNull (type.GetProperty ("IntInstBlue", flags), "#M25");
-#endif
                        Assert.IsNull (type.GetProperty ("PrivStatBlue", flags), "#M26");
                        Assert.IsNull (type.GetProperty ("ProtStatBlue", flags), "#M27");
                        Assert.IsNull (type.GetProperty ("ProIntStatBlue", flags), "#M28");
@@ -1566,7 +1503,6 @@ namespace MonoTests.System
                {
                }
 
-#if NET_2_0
                [Test]
                public void StructLayoutAttribute ()
                {
@@ -1582,7 +1518,6 @@ namespace MonoTests.System
                        Assert.AreEqual (LayoutKind.Explicit, attr3.Value);
                        Assert.AreEqual (CharSet.Unicode, attr3.CharSet);
                }
-#endif
 #endif // TARGET_JVM
 
                [Test]
@@ -1591,6 +1526,20 @@ namespace MonoTests.System
                        Assert.AreEqual (null, typeof (NoNamespaceClass).Namespace);
                }
 
+               [Test]
+               public void GenericParameterNamespace ()
+               {
+                       var t = typeof (Foo<>).GetGenericArguments () [0];
+
+                       Assert.AreEqual ("T", t.Name);
+                       Assert.AreEqual ("MonoTests.System", t.Namespace);
+
+                       var s = typeof (Gazonk).GetMethod ("Bang").GetGenericArguments () [0];
+
+                       Assert.AreEqual ("S", s.Name);
+                       Assert.AreEqual ("MonoTests.System", s.Namespace);
+               }
+
                public static void Reflected (ref int a)
                {
                }
@@ -1621,7 +1570,6 @@ namespace MonoTests.System
                        Assert.IsNotNull (typeof (TypeTest).GetField ("afield", BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase));
                }
 
-#if NET_2_0
                public int Count {
                        internal get {
                                return 0;
@@ -1637,7 +1585,6 @@ namespace MonoTests.System
                        Assert.IsNotNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.Public));
                        Assert.IsNull (typeof (TypeTest).GetProperty ("Count", BindingFlags.Instance | BindingFlags.NonPublic));
                }
-#endif
 
                [Test]
                public void IsAbstract ()
@@ -1649,12 +1596,10 @@ namespace MonoTests.System
                        Assert.IsFalse (typeof (TimeSpan).IsAbstract, "#5");
                        Assert.IsTrue (typeof (TextReader).IsAbstract, "#6");
 
-#if NET_2_0
                        // LAMESPEC:
                        // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=286308
                        Type [] typeArgs = typeof (List<>).GetGenericArguments ();
                        Assert.IsFalse (typeArgs [0].IsAbstract, "#7");
-#endif
                }
 
                [Test]
@@ -1907,11 +1852,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#B3");
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.IsNotNull (ex.ParamName, "#B5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#B6");
-#endif
                        }
                }
 
@@ -1930,11 +1871,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsNotNull (ex.ParamName, "#5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#6");
-#endif
                        }
                }
 
@@ -1954,11 +1891,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#A3");
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.IsNotNull (ex.ParamName, "#A5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#A6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#A6");
-#endif
                        }
 
                        try {
@@ -1973,11 +1906,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#B3");
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.IsNotNull (ex.ParamName, "#B5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#B6");
-#endif
                        }
                }
 
@@ -2023,11 +1952,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsNotNull (ex.ParamName, "#5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#6");
-#endif
                        }
                }
 
@@ -2058,11 +1983,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNull (ex.InnerException, "#A3");
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.IsNotNull (ex.ParamName, "#A5");
-#if NET_2_0
                                Assert.AreEqual ("bindingFlags", ex.ParamName, "#6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#6");
-#endif
                        }
 
                        try {
@@ -2070,7 +1991,6 @@ PublicKeyToken=b77a5c561934e089"));
                                        BindingFlags.Static | BindingFlags.SetField,
                                        null, null, null);
                                Assert.Fail ("#B1");
-#if NET_2_0
                        } catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
@@ -2078,21 +1998,6 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.IsNotNull (ex.ParamName, "#B5");
                                Assert.AreEqual ("providedArgs", ex.ParamName, "#B6");
                        }
-#else
-                       } catch (ArgumentException ex) {
-                               // Only the field value can be specified to set
-                               // a field value
-                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
-                               Assert.IsNull (ex.InnerException, "#B3");
-                               Assert.IsNotNull (ex.Message, "#B4");
-                               Assert.IsNotNull (ex.ParamName, "#B5");
-#if NET_2_0
-                               Assert.AreEqual ("bindingFlags", ex.ParamName, "#B6");
-#else
-                               Assert.AreEqual ("invokeAttr", ex.ParamName, "#B6");
-#endif
-                       }
-#endif
                }
 
                [Test] // bug #336841
@@ -2120,7 +2025,7 @@ PublicKeyToken=b77a5c561934e089"));
                [Test] // bug #348522
                public void InvokeMember_WithoutDefaultValue ()
                {
-                       BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;;
+                       BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod;
                        try {
                                typeof (Bug348522).InvokeMember ("Test", flags, new FirstMethodBinder (), new Bug348522(),
                                        new object [] {Missing.Value}, null, null, null);
@@ -2135,6 +2040,25 @@ PublicKeyToken=b77a5c561934e089"));
                        }
                }
 
+           [Test]
+               public void TestMissing () {
+                       Assert.AreEqual (Type.Missing, Missing.Value);
+               }
+
+               [Test]
+               public void InvokeMember_OutParam ()
+               {
+                       object[] args = new object[] { new string [0] };
+                       typeof (TypeTest).InvokeMember ("OutTest", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, args);
+                       Assert.IsTrue (args [0] is string[]);
+                       Assert.AreEqual (10, ((string[])args[0]).Length);
+               }
+
+               public static void OutTest (out string[] a1)
+               {
+                       a1 = new string [10];
+               }
+
                class X
                {
                        public static int Value;
@@ -2441,9 +2365,7 @@ PublicKeyToken=b77a5c561934e089"));
                }
 
                [Test] // bug #82431
-#if NET_2_0
                [Category ("NotWorking")]
-#endif
                public void IsDefined_Inherited ()
                {
                        Assert.IsFalse (typeof (CA).IsDefined (typeof (NemerleAttribute), false), "#C1");
@@ -2461,13 +2383,8 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), false), "#D4");
                        Assert.IsTrue (typeof (BBA).IsDefined (typeof (NemerleAttribute), true), "#D5");
                        Assert.IsTrue (typeof (BBA).IsDefined (typeof (VolatileModifier), true), "#D6");
-#if NET_2_0
                        Assert.IsTrue (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
                        Assert.IsTrue (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
-#else
-                       Assert.IsFalse (typeof (BBA).IsDefined (typeof (FooAttribute), true), "#D7");
-                       Assert.IsFalse (typeof (BBA).IsDefined (typeof (BarAttribute), true), "#D8");
-#endif
 
                        Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (InheritAttribute), false), "#E1");
                        Assert.IsTrue (typeof (bug82431A1).IsDefined (typeof (NotInheritAttribute), false), "#E2");
@@ -2476,11 +2393,7 @@ PublicKeyToken=b77a5c561934e089"));
 
                        Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), false), "#F1");
                        Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), false), "#F2");
-#if NET_2_0
                        Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
-#else
-                       Assert.IsTrue (typeof (bug82431A2).IsDefined (typeof (InheritAttribute), true), "#F3");
-#endif
                        Assert.IsFalse (typeof (bug82431A2).IsDefined (typeof (NotInheritAttribute), true), "#F4");
 
                        Assert.IsTrue (typeof (bug82431A3).IsDefined (typeof (InheritAttribute), false), "#G1");
@@ -2519,11 +2432,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
                                Assert.AreEqual ("TypeName", ex.ParamName, "#5");
-#else
-                               Assert.AreEqual ("className", ex.ParamName, "#5");
-#endif
                        }
                }
 
@@ -2537,11 +2446,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
                                Assert.AreEqual ("TypeName", ex.ParamName, "#5");
-#else
-                               Assert.AreEqual ("className", ex.ParamName, "#5");
-#endif
                        }
                }
 
@@ -2555,11 +2460,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
                                Assert.AreEqual ("TypeName", ex.ParamName, "#5");
-#else
-                               Assert.AreEqual ("className", ex.ParamName, "#5");
-#endif
                        }
                }
 
@@ -2605,20 +2506,7 @@ PublicKeyToken=b77a5c561934e089"));
                {
                        RuntimeTypeHandle handle = new RuntimeTypeHandle ();
 
-#if NET_2_0
                        Assert.IsNull (Type.GetTypeFromHandle (handle));
-#else
-                       try {
-                               Type.GetTypeFromHandle (handle);
-                               Assert.Fail ("#1");
-                       } catch (ArgumentException ex) {
-                               // Handle is not initialized
-                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsNull (ex.ParamName, "#5");
-                       }
-#endif
                }
 
                [Test]
@@ -2631,11 +2519,7 @@ PublicKeyToken=b77a5c561934e089"));
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
                                Assert.IsNull (ex.ParamName, "#5");
-#else
-                               Assert.AreEqual ("o", ex.ParamName, "#5");
-#endif
                        }
                }
 
@@ -2793,7 +2677,6 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsNull (typeof (TheEnum).GetElementType (), "#1");
                }
 
-#if NET_2_0
                [Test]
                public void FullNameGenerics ()
                {
@@ -2882,6 +2765,14 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsTrue (typeof (Nullable<int>[]).IsInstanceOfType (new Nullable<int> [0]));
                }
 
+               [Test]
+               public void IsInstanceOfType_Null ()
+               {
+                       Assert.IsFalse (typeof (int).IsInstanceOfType (null), "int");
+                       Assert.IsFalse (typeof (object).IsInstanceOfType (null), "object");
+                       Assert.IsFalse (typeof (int?).IsInstanceOfType (null), "int?");
+               }
+
                [Test]
                public void ByrefType ()
                {
@@ -2892,6 +2783,21 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.IsNull (byref_type_param.DeclaringType);
                }
 
+               [Test]
+               [ExpectedException (typeof (TypeLoadException))]
+               public void MakeByRefByRef ()
+               {
+                       typeof (int).MakeByRefType ().MakeByRefType ();
+               }
+
+               [Test]
+               public void MakeArrayTypeTest ()
+               {
+                       // This should not crash:
+                       typeof (void).MakeArrayType ();
+               }
+               
+
                [ComVisible (true)]
                public class ComFoo<T> {
                }
@@ -2981,7 +2887,6 @@ PublicKeyToken=b77a5c561934e089"));
                }
 
                [Test] //bug #331199
-               //FIXME: 2.0 SP 1 has a diferent behavior
                public void MakeGenericType_UserDefinedType ()
                {
                        Type ut = new UserType (typeof (int));
@@ -2992,7 +2897,7 @@ PublicKeyToken=b77a5c561934e089"));
                        Type arg = t.GetGenericArguments () [0];
                        Assert.IsNotNull (arg, "#B1");
                        Assert.IsFalse (arg.IsGenericType, "#B2");
-                       Assert.AreEqual (typeof (int), arg, "#B3");
+                       Assert.AreEqual (ut, arg, "#B3");
                }
 
                [Category ("NotWorking")]
@@ -3120,7 +3025,6 @@ PublicKeyToken=b77a5c561934e089"));
        public void GenericParameterPositionUserType () {
                Assert.IsTrue (new UserType(null).GenericParameterPosition == 0);
        }
-#endif
 
                [Test]
                public void TypeGetMemberReturnTypeTest ()
@@ -3158,6 +3062,155 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.AreEqual (t1, t2);
                }
 
+
+               [Test]
+               public void Bug506757 ()
+               {
+                       AssemblyName assemblyName = new AssemblyName ();
+                       assemblyName.Name = "customMod";
+                       assemblyName.Version = new Version (1, 2, 3, 4);
+       
+                       AssemblyBuilder assembly 
+                               = Thread.GetDomain().DefineDynamicAssembly(
+                                         assemblyName, AssemblyBuilderAccess.RunAndSave);
+       
+                       ModuleBuilder module = assembly.DefineDynamicModule("res.exe", "res.exe");
+       
+                       TypeBuilder type0 = module.DefineType ("Base", TypeAttributes.Public, typeof (object));
+                       TypeBuilder type1 = module.DefineType ("Middle", TypeAttributes.Public, type0);
+                       TypeBuilder type2 = module.DefineType ("End", TypeAttributes.Public, type1);
+       
+                       MethodAttributes attrs0 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
+                                                 MethodAttributes.NewSlot | MethodAttributes.FamORAssem;
+       
+                       MethodAttributes attrs1 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
+                                                 MethodAttributes.FamORAssem;
+       
+                       MethodAttributes attrs2 = MethodAttributes.Virtual | MethodAttributes.HideBySig |
+                                                 MethodAttributes.Public;
+       
+       
+                       MethodBuilder m0 = type0.DefineMethod ("Tst", attrs0, typeof (void), null);
+                       m0.GetILGenerator ().Emit (OpCodes.Ret);
+       
+                       MethodBuilder m1 = type1.DefineMethod ("Tst", attrs1, typeof (void), null);
+                       m1.GetILGenerator ().Emit (OpCodes.Ret);
+       
+                       MethodBuilder m2 = type2.DefineMethod ("Tst", attrs2, typeof (void), null);
+                       m2.GetILGenerator ().Emit (OpCodes.Ret);
+       
+       
+                       type0.CreateType ();
+                       type1.CreateType ();
+                       Type t2 = type2.CreateType ();
+       
+                       foreach (var m in t2.GetMethods (BindingFlags.Instance | BindingFlags.NonPublic))
+                               Assert.IsTrue (m.DeclaringType == typeof (object), String.Format ("{0}::{1}", m.DeclaringType, m.Name));
+               }
+
+               [Test]
+               public void MakeArrayTypeOfOneDimension ()
+               {
+                       Type vector = typeof (int).MakeArrayType ();
+                       Type szarray = typeof (int).MakeArrayType (1);
+
+                       Assert.AreNotEqual (vector, szarray, "#1");
+                       Assert.AreEqual ("Int32[]", vector.Name, "#2");
+                       Assert.AreEqual ("Int32[*]", szarray.Name, "#3");
+               }
+
+               public class DeclaringMethodFoo {
+                       public void Test<T> (T t) {}
+                       public void Test2<T> (ref T t) {}
+               }
+
+               public class DeclaringMethodBar<T> {
+                       public void Test2 (ref T t) {}
+               }
+
+               [Test]
+               public void DeclaringMethodOnlyWorksWithGenericArgs ()
+               {
+               MethodInfo testMethod = typeof (DeclaringMethodFoo).GetMethod ("Test");
+               MethodBase otherMethod = testMethod.GetParameters ()[0].ParameterType.DeclaringMethod;
+
+                       Assert.AreEqual (testMethod, otherMethod,"#1");
+
+                       Assert.IsNull (typeof (DeclaringMethodBar<>).GetGenericArguments ()[0].DeclaringMethod, "#2");
+
+                       try {
+                               var x = typeof (int).DeclaringMethod;
+                               Assert.Fail ("#3");
+                       } catch (InvalidOperationException) {}
+
+                       try {
+                               var x = typeof (DeclaringMethodFoo).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
+                               Assert.Fail ("#4");
+                       } catch (InvalidOperationException) {}
+
+                       try {
+                               var x = typeof (DeclaringMethodBar<>).GetMethod ("Test2").GetParameters () [0].ParameterType.DeclaringMethod;
+                               Assert.Fail ("#5");
+                       } catch (InvalidOperationException) {}
+
+               }
+
+               [Test]
+               public void GetArrayRankThrowsForNonArrayType ()
+               {
+                       Assert.AreEqual (1, typeof (int[]).GetArrayRank (), "#1");
+                       Assert.AreEqual (2, typeof (int[,]).GetArrayRank (), "#2");
+                       try {
+                               typeof (int).GetArrayRank ();
+                               Assert.Fail ("#3");
+                       } catch (ArgumentException) {}
+               }
+
+               [Test] //Bug #564379
+               public void GetMethodsReturnPublicMethodsInInterfaces ()
+               {
+                       Type t = typeof (NonClosingStream);
+                       MethodInfo[] methods = t.GetMethods (BindingFlags.Public | BindingFlags.Instance);
+
+                       Assert.AreEqual (5, methods.Length, "#1");
+                       int id = 2;
+
+                       foreach (var m in methods) {
+                               if (m.Name.Equals ("ToString"))
+                                       Assert.IsTrue (m.DeclaringType == typeof (NonClosingStream), "#" + id);
+                               else if (m.Name.Equals ("Dispose") && m.GetParameters ().Length == 0)
+                                       Assert.IsTrue (m.DeclaringType == typeof (Stream), "#" + id);
+                               else if (m.Name.Equals ("Equals") || m.Name.Equals ("GetHashCode") || m.Name.Equals ("GetType"))
+                                       Assert.IsTrue (m.DeclaringType == typeof (object), "#" + id);
+                               else
+                                       Assert.Fail ("invalid method " + m);
+                               ++id;
+                       }
+               }
+
+               public abstract class Stream : IDisposable
+               {
+                       public void Dispose ()
+                       {
+                               Console.WriteLine ("stream::dispose");
+                       }
+
+                       protected virtual void Dispose (bool disposing)
+                       {
+                       }
+               }
+
+               public class NonClosingStream 
+                       : Stream, IDisposable
+               {
+                       void  IDisposable.Dispose()
+                       {
+                               Console.WriteLine ("ncs::dispose");
+                       }
+
+                       public override string ToString () { return ""; }
+               }
+
                static bool ContainsProperty (PropertyInfo [] props, string name)
                {
                        foreach (PropertyInfo p in props)
@@ -3471,7 +3524,6 @@ PublicKeyToken=b77a5c561934e089"));
                }
        }
 
-#if NET_2_0
        class UserType : Type
        {
                protected Type type;
@@ -3482,7 +3534,7 @@ PublicKeyToken=b77a5c561934e089"));
        
                public override Type UnderlyingSystemType { get { return this.type; } }
        
-               public override Assembly Assembly { get { return this.type.Assembly; } }
+               public override Assembly Assembly { get { return this.type == null ? null : this.type.Assembly; } }
        
                public override string AssemblyQualifiedName { get { return null; } }
        
@@ -3663,5 +3715,4 @@ PublicKeyToken=b77a5c561934e089"));
                        return type.GetHashCode();
                }
        }
-#endif
 }