public void ReturnParameter ()
{
ParameterInfo pi = typeof (MethodInfoTest).GetMethod ("return_parameter_test").ReturnParameter;
-
- Assert.AreEqual (typeof (int), pi.ParameterType);
- Assert.AreEqual (-1, pi.Position);
- // This fails on MS
- //Assert.AreEqual (True, pi.IsRetval);
+ Assert.AreEqual (typeof (int), pi.ParameterType, "#1");
+ Assert.AreEqual (-1, pi.Position, "#2");
+ // MS always return false here
+ //Assert.IsTrue (pi.IsRetval, "#3");
}
#if !TARGET_JVM // ReflectionOnly is not supported yet on TARGET_JVM
[Test]
- [ExpectedException (typeof (InvalidOperationException))]
- public void InvokeOnRefOnlyAssembly ()
+ public void InvokeOnRefOnlyAssembly ()
{
Assembly a = Assembly.ReflectionOnlyLoad (typeof (MethodInfoTest).Assembly.FullName);
Type t = a.GetType (typeof (RefOnlyMethodClass).FullName);
MethodInfo m = t.GetMethod ("RefOnlyMethod", BindingFlags.Static | BindingFlags.NonPublic);
-
- m.Invoke (null, new object [0]);
+ try {
+ m.Invoke (null, new object [0]);
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException ex) {
+ // The requested operation is invalid in the
+ // ReflectionOnly context
+ Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ }
}
#endif // TARGET_JVM
MethodInfo generic_method = method.MakeGenericMethod (arguments);
kvp = (KeyValuePair<string, uint>)generic_method.Invoke (null, new object [] { kvp });
- Assert.AreEqual ("a", kvp.Key);
- Assert.AreEqual (21, kvp.Value);
+ Assert.AreEqual ("a", kvp.Key, "#1");
+ Assert.AreEqual (21, kvp.Value, "#2");
}
public static KeyValuePair<T1, T2> Go <T1, T2> (KeyValuePair <T1, T2> kvp)
strArg.Add ("test");
}
- public void MakeGenericMethodArgsMismatchFoo<T> () {}
+ public void MakeGenericMethodArgsMismatchFoo<T> ()
+ {
+ }
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void MakeGenericMethodArgsMismatch ()
{
MethodInfo gmi = this.GetType ().GetMethod (
- "MakeGenericMethodArgsMismatchFoo")
- .MakeGenericMethod ();
+ "MakeGenericMethodArgsMismatchFoo");
+ try {
+ gmi.MakeGenericMethod ();
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // The type or method has 1 generic parameter(s),
+ // but 0 generic argument(s) were provided. A
+ // generic argument must be provided for each
+ // generic parameter
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
}
public void SimpleGenericMethod<TFoo, TBar> () {}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void MakeGenericMethodWithNullArray ()
{
MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
-
- gmi.MakeGenericMethod ((Type []) null);
+ try {
+ gmi.MakeGenericMethod ((Type []) null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("methodInstantiation", ex.ParamName, "#5");
+ }
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void MakeGenericMethodWithNullValueInTypesArray ()
{
MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
-
- gmi.MakeGenericMethod (new Type [] { typeof (int), null });
+ try {
+ gmi.MakeGenericMethod (new Type [] { typeof (int), null });
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
}
public static int? pass_nullable (int? i)
// Test conversion of vtype to a nullable type for the this argument
PropertyInfo pi = typeof (Nullable <int>).GetProperty ("HasValue");
- Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
+ Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
PropertyInfo pi2 = typeof (Nullable <int>).GetProperty ("Value");
- Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
+ Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
}
public static void foo_generic<T> ()
Assert.AreEqual (true, mi.IsGenericMethod, "#1");
MethodInfo mi2 = mi.MakeGenericMethod (new Type[] { typeof (int) });
Assert.AreEqual (true, mi2.IsGenericMethod, "#2");
-
MethodInfo mi3 = typeof (GenericHelper<int>).GetMethod ("Test");
Assert.AreEqual (false, mi3.IsGenericMethod, "#3");
}
public void IsGenericMethodDefinition ()
{
MethodInfo m1 = typeof (A<>).GetMethod ("Foo");
- Assert.IsTrue (m1.IsGenericMethod);
- Assert.IsTrue (m1.IsGenericMethodDefinition);
+ Assert.IsTrue (m1.IsGenericMethod, "#A1");
+ Assert.IsTrue (m1.IsGenericMethodDefinition, "#A2");
MethodInfo m2 = typeof (A<int>).GetMethod ("Foo");
- Assert.IsTrue (m2.IsGenericMethod);
- Assert.IsTrue (m2.IsGenericMethodDefinition);
+ Assert.IsTrue (m2.IsGenericMethod, "#B1");
+ Assert.IsTrue (m2.IsGenericMethodDefinition, "#B2");
MethodInfo m3 = m2.MakeGenericMethod (typeof (int));
- Assert.IsTrue (m3.IsGenericMethod);
- Assert.IsFalse (m3.IsGenericMethodDefinition);
+ Assert.IsTrue (m3.IsGenericMethod, "#C1");
+ Assert.IsFalse (m3.IsGenericMethodDefinition, "#C2");
}
[Test]
MethodInfo mi2 = typeof (MyList<int>).GetMethod ("ConvertAll");
Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[T,TOutput]",
- mi1.GetParameters () [0].ParameterType.ToString ());
+ mi1.GetParameters () [0].ParameterType.ToString (), "#A1");
Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[System.Int32,TOutput]",
- mi2.GetParameters () [0].ParameterType.ToString ());
- Assert.IsTrue (mi1.IsGenericMethod);
- Assert.IsTrue (mi1.IsGenericMethodDefinition);
- Assert.IsTrue (mi2.IsGenericMethod);
- Assert.IsTrue (mi2.IsGenericMethodDefinition);
+ mi2.GetParameters () [0].ParameterType.ToString (), "#A2");
+ Assert.IsTrue (mi1.IsGenericMethod, "#A3");
+ Assert.IsTrue (mi1.IsGenericMethodDefinition, "#A4");
+ Assert.IsTrue (mi2.IsGenericMethod, "#A5");
+ Assert.IsTrue (mi2.IsGenericMethodDefinition, "#A6");
MethodInfo mi3 = mi2.GetGenericMethodDefinition ();
- Assert.IsTrue (mi3.IsGenericMethod);
- Assert.IsTrue (mi3.IsGenericMethodDefinition);
-
- // ensure it's the same object, not just equal
- Assert.IsTrue (mi2 == mi3);
+ Assert.IsTrue (mi3.IsGenericMethod, "#B1");
+ Assert.IsTrue (mi3.IsGenericMethodDefinition, "#B2");
+ Assert.AreSame (mi2, mi3, "#B3");
}
public class MyList<T>
class GenericHelper<T>
{
public void Test (T t)
- { }
+ {
+ }
}
#endif
}
}
}
-
#if NET_2_0
public enum ParamEnum {
None = 0,
Bar = 2
};
- public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n) {
+ public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n)
+ {
}
+
#if !TARGET_JVM // No support for extern methods in TARGET_JVM
[DllImport ("foo")]
public extern static void marshalAsMethod (
Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2");
}
- // See bug: 339013
- [Test]
+ [Test] // bug #339013
public void TestDefaultValues ()
{
ParameterInfo [] pi = typeof (ParameterInfoTest).GetMethod ("Sample").GetParameters ();
public void Sample (int a, [Optional] int b)
{
}
-
+
[Test]
public void PseudoCustomAttributes () {
ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#D3");
#endif
}
+
+ [Test] // bug #342536
+ public void Generics_Name ()
+ {
+ MethodInfo mi;
+ Type type;
+ ParameterInfo [] info;
+
+ type = typeof (BaseType<string>);
+
+ mi = type.GetMethod ("GetItems");
+ Assert.IsNotNull (mi, "#A1");
+ info = mi.GetParameters ();
+ Assert.AreEqual (1, info.Length, "#A2");
+ Assert.AreEqual ("count", info [0].Name, "#A3");
+
+ mi = type.GetMethod ("Add");
+ Assert.IsNotNull (mi, "#B1");
+ info = mi.GetParameters ();
+ Assert.AreEqual (2, info.Length, "#B2");
+ Assert.AreEqual ("item", info [0].Name, "#B3");
+ Assert.AreEqual ("index", info [1].Name, "#B4");
+
+ mi = type.GetMethod ("Create");
+ Assert.IsNotNull (mi, "#C1");
+ info = mi.GetParameters ();
+ Assert.AreEqual (2, info.Length, "#C2");
+ Assert.AreEqual ("x", info [0].Name, "#C3");
+ Assert.AreEqual ("item", info [1].Name, "#C4");
+ }
+
+ public class BaseType <T>
+ {
+ public void GetItems (int count)
+ {
+ }
+
+ public void Add (T item, int index)
+ {
+ }
+
+ public V Create <V> (int x, T item)
+ {
+ return default (V);
+ }
+ }
#endif
}
}