+
+ [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 ""; }
+ }
+