using System.Collections.Generic;
using System.IO;
using System.Reflection;
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
using System.Runtime.InteropServices;
[TestFixture]
public class TypeTest
{
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME
private ModuleBuilder module;
#endif
const string ASSEMBLY_NAME = "MonoTests.System.TypeTest";
{
AssemblyName assemblyName = new AssemblyName ();
assemblyName.Name = ASSEMBLY_NAME;
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME
var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (
assemblyName, AssemblyBuilderAccess.RunAndSave, Path.GetTempPath ());
module = assembly.DefineDynamicModule ("module1");
object o = Array.CreateInstance (typeof (global::System.TypedReference), 1);
}
+ [Test]
+ public void MakeArrayTypeLargeRank ()
+ {
+ Assert.Throws<TypeLoadException> (delegate () {
+ typeof (int).MakeArrayType (33);
+ });
+ }
+
[ComVisible (true)]
public class ComFoo<T> {
}
}
[Test]
-#if MONOTOUCH || MOBILE_STATIC
+#if MONOTOUCH || FULL_AOT_RUNTIME
[ExpectedException (typeof (NotSupportedException))]
#endif
public void MakeGenericType_UserDefinedType ()
}
[Test]
-#if MONOTOUCH || MOBILE_STATIC
+#if MONOTOUCH || FULL_AOT_RUNTIME
[ExpectedException (typeof (NotSupportedException))]
#endif
public void MakeGenericType_NestedUserDefinedType ()
}
[Test]
-#if MONOTOUCH || MOBILE_STATIC
+#if MONOTOUCH || FULL_AOT_RUNTIME
[ExpectedException (typeof (NotSupportedException))]
#endif
public void TestMakeGenericType_UserDefinedType_DotNet20SP1 ()
}
[Test]
-#if MONOTOUCH || MOBILE_STATIC
+#if MONOTOUCH || FULL_AOT_RUNTIME
[ExpectedException (typeof (NotSupportedException))]
#endif
public void MakeGenericType_BadUserType ()
Assert.AreSame (expectedType, r, "#2");
}
+ public class BConstrained<Y> where Y : BConstrained<Y> {
+ }
+
+ public class AConstrained<X> : BConstrained<AConstrained<X>> {
+ }
+
+ [Test] // Bug https://bugzilla.xamarin.com/show_bug.cgi?id=54485
+ public void MakeGenericType_GTD_Constraint ()
+ {
+ // This is pretty weird, but match .NET behavior (note
+ // that typeof(BConstrained<AConstrained<>>) is a
+ // compile-time error with roslyn, but it's apparently
+ // an ok thing to make with reflection.
+ var tb = typeof (BConstrained<>);
+ var ta = typeof (AConstrained<>);
+ var result = tb.MakeGenericType (ta);
+ Assert.IsNotNull (result, "#1");
+ // lock down the answer to match what .NET makes
+ Assert.IsTrue (result.IsGenericType, "#2");
+ Assert.AreEqual (tb, result.GetGenericTypeDefinition (), "#3");
+ var bargs = result.GetGenericArguments ();
+ Assert.AreEqual (1, bargs.Length, "#4");
+ var arg = bargs [0];
+ Assert.IsTrue (arg.IsGenericType, "#5");
+ // N.B. evidently AConstrained`1 and AConstrained`1<!0> are the same type
+ Assert.IsTrue (arg.IsGenericTypeDefinition, "#6");
+ Assert.AreEqual (ta, arg.GetGenericTypeDefinition (), "#7");
+ var aargs = arg.GetGenericArguments ();
+ Assert.AreEqual (1, aargs.Length, "#8");
+ Assert.AreEqual (ta.GetGenericArguments () [0], aargs [0], "#9");
+ }
+
[Test]
public void EqualsUserType () {
UserType2 t1 = new UserType2(null);
Assert.AreEqual (t1, t2);
}
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME
[Test]
public void SpaceAfterComma () {
string strType = "System.Collections.Generic.Dictionary`2[[System.Int32,mscorlib], [System.String,mscorlib]],mscorlib";
}
#endif
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME
[Test]
public void Bug506757 ()
{
MustTLE (string.Format ("{0}ZZZZ,{1}", typeof (MyRealEnum).FullName, aqn));
}
+ [Test]
+ public void GetTypeExceptionMsg () {
+ string typeName = "system.int32, foo";
+ try {
+ Type.GetType(typeName, true, false);
+ } catch (TypeLoadException ex) {
+ Assert.IsTrue (ex.Message.Contains ("system.int32"));
+ Assert.IsTrue (ex.Message.Contains ("foo"));
+ }
+ }
+
delegate void MyAction<in T>(T ag);
[Test] //bug #668506
}
-#if !MONOTOUCH && !MOBILE_STATIC
+#if !MONOTOUCH && !FULL_AOT_RUNTIME && !MONOMAC
[Test]
[Category ("AndroidNotWorking")] // requires symbol writer
public void FullNameGetTypeParseEscapeRoundtrip () // bug #26384
var nm = new AssemblyName ("asm");
var ab = AssemblyBuilder.DefineDynamicAssembly (nm,
AssemblyBuilderAccess.Run);
- var mb = ab.DefineDynamicModule("m", true);
+ var mb = ab.DefineDynamicModule("m", false);
var tb = mb.DefineType ("NameSpace,+*&[]\\.Type,+*&[]\\",
TypeAttributes.Class | TypeAttributes.Public);
}
#endif
+
+ [Test]
+ public void GetTypeBadArity()
+ {
+ // Regression test for #46250
+ try {
+ Type.GetType ("System.Collections.Generic.Dictionary`2[System.String]", true);
+ Assert.Fail ("Did not throw an exception (#1)");
+ } catch (ArgumentException) {
+ }
+
+ try {
+ Type.GetType ("System.Collections.Generic.Dictionary`2[System.String,System.Int32,System.Int64]", true);
+ Assert.Fail ("Did not throw an exception (#2)");
+ } catch (ArgumentException) {
+ }
+ }
+
public abstract class Stream : IDisposable
{
public void Dispose ()