Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/Reflection')
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs40
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs23
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs18
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs8
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs18
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs15
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs33
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs36
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs40
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs161
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs23
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs24
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs64
22 files changed, 661 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs
new file mode 100644
index 000000000..147c31c60
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.Reflection
+{
+ [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")]
+ [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)]
+ [KeptAssembly ("library.dll")]
+ [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency")]
+ public class AssemblyImportedViaReflection
+ {
+ public static void Main ()
+ {
+ const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency, library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var res = Type.GetType (newAssemblyType, true);
+ return;
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs
new file mode 100644
index 000000000..5f4e8af1e
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs
@@ -0,0 +1,40 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.Reflection.Dependencies;
+
+namespace Mono.Linker.Tests.Cases.Reflection
+{
+ [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")]
+ [SetupCompileBefore ("base.dll", new [] { "Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs" })]
+ [SetupCompileBefore ("reflection.dll", new [] { "Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs" }, references: new [] {"base.dll"}, addAsReference: false)]
+ [KeptAssembly ("base.dll")]
+ [KeptAssembly ("reflection.dll")]
+ [KeptMemberInAssembly ("base.dll", typeof (AssemblyImportedViaReflectionWithDerivedType_Base), "Method()")]
+ [KeptMemberInAssembly ("reflection.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyImportedViaReflectionWithDerivedType_Reflect", "Method()")]
+ public class AssemblyImportedViaReflectionWithDerivedType
+ {
+ public static void Main ()
+ {
+ // Cause a the new assembly to be included via reflection usage
+ const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyImportedViaReflectionWithDerivedType_Reflect, reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var res = Type.GetType (newAssemblyType, true);
+
+ // Foo and the reflection assembly both have a class the inherits from the base type.
+ // by using `Method` here and marking the reflection type above, we've introduced a requirement that `Method` be marked on the type in the reflection assembly as well
+ var obj = new Foo ();
+ var val = obj.Method ();
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (AssemblyImportedViaReflectionWithDerivedType_Base))]
+ class Foo : AssemblyImportedViaReflectionWithDerivedType_Base {
+ [Kept]
+ public override string Method ()
+ {
+ return "Foo";
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs
new file mode 100644
index 000000000..716207d22
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs
@@ -0,0 +1,23 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.Reflection
+{
+ [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")]
+ [SetupCompileBefore ("reference.dll", new [] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)]
+ [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependencyWithReference.cs" }, references: new []{"reference.dll"}, addAsReference: false)]
+ [KeptAssembly ("reference.dll")]
+ [KeptAssembly ("library.dll")]
+ [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependencyWithReference")]
+ [KeptTypeInAssembly ("reference.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency")]
+ public class AssemblyImportedViaReflectionWithReference
+ {
+ public static void Main ()
+ {
+ const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependencyWithReference, library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var res = Type.GetType (newAssemblyType, true);
+ return;
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
new file mode 100644
index 000000000..16851b0cf
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection
+{
+ public class ConstructorUsedViaReflection {
+ public static void Main ()
+ {
+ var constructor = typeof (OnlyUsedViaReflection).GetConstructor (BindingFlags.Public, null, new Type[]{}, new ParameterModifier[]{});
+ constructor.Invoke (null, new object[] { });
+ }
+
+ [Kept]
+ private class OnlyUsedViaReflection {
+ [Kept]
+ public OnlyUsedViaReflection ()
+ { }
+
+ [Kept]
+ public OnlyUsedViaReflection(string bar)
+ { }
+
+ private OnlyUsedViaReflection (int foo)
+ { }
+
+ protected OnlyUsedViaReflection(int foo, int bar)
+ { }
+
+ internal OnlyUsedViaReflection(int foo, int bar, int baz)
+ { }
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs
new file mode 100644
index 000000000..84339ad4b
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Reflection.Dependencies
+{
+ public class AssemblyDependency
+ {
+ public AssemblyDependency ()
+ {
+ }
+
+ public static void UsedToKeepReferenceAtCompileTime ()
+ {
+ }
+
+ class TypeThatIsUsedViaReflection {
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs
new file mode 100644
index 000000000..889b5e141
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs
@@ -0,0 +1,4 @@
+namespace Mono.Linker.Tests.Cases.Reflection.Dependencies {
+ public class AssemblyDependencyWithReference : AssemblyDependency {
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs
new file mode 100644
index 000000000..6323951ee
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs
@@ -0,0 +1,5 @@
+namespace Mono.Linker.Tests.Cases.Reflection.Dependencies {
+ public abstract class AssemblyImportedViaReflectionWithDerivedType_Base {
+ public abstract string Method ();
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs
new file mode 100644
index 000000000..e0c1bcb2a
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs
@@ -0,0 +1,8 @@
+namespace Mono.Linker.Tests.Cases.Reflection.Dependencies {
+ public class AssemblyImportedViaReflectionWithDerivedType_Reflect : AssemblyImportedViaReflectionWithDerivedType_Base {
+ public override string Method ()
+ {
+ return "Reflect";
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
new file mode 100644
index 000000000..774a46489
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
@@ -0,0 +1,18 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class EventUsedViaReflection {
+ public static void Main ()
+ {
+ var eventInfo = typeof (EventUsedViaReflection).GetEvent ("Event");
+ eventInfo.GetAddMethod (false);
+ }
+
+ [Kept]
+ [KeptBackingField]
+ [KeptEventAddMethod]
+ [KeptEventRemoveMethod]
+ event EventHandler<EventArgs> Event;
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
new file mode 100644
index 000000000..c7c77abb5
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
@@ -0,0 +1,15 @@
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class FieldUsedViaReflection {
+ public static void Main ()
+ {
+ var field = typeof (FieldUsedViaReflection).GetField ("field");
+ field.GetValue (null);
+ }
+
+ [Kept]
+ static int field;
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
new file mode 100644
index 000000000..39a7e12f4
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
@@ -0,0 +1,33 @@
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class MethodUsedViaReflection {
+ public static void Main ()
+ {
+ var method = typeof (MethodUsedViaReflection).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.NonPublic);
+ method.Invoke (null, new object[] { });
+ }
+
+ [Kept]
+ private static int OnlyCalledViaReflection ()
+ {
+ return 42;
+ }
+
+ private int OnlyCalledViaReflection (int foo)
+ {
+ return 43;
+ }
+
+ public int OnlyCalledViaReflection (int foo, int bar)
+ {
+ return 44;
+ }
+
+ public static int OnlyCalledViaReflection (int foo, int bar, int baz)
+ {
+ return 45;
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs
new file mode 100644
index 000000000..7a2a4ae10
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class MethodUsedViaReflectionWithDefaultBindingFlags {
+ public static void Main ()
+ {
+ var method = typeof (MethodUsedViaReflectionWithDefaultBindingFlags).GetMethod ("OnlyCalledViaReflection");
+ method.Invoke (null, new object[] { });
+ }
+
+ [Kept]
+ private static int OnlyCalledViaReflection ()
+ {
+ return 42;
+ }
+
+ [Kept]
+ private int OnlyCalledViaReflection (int foo)
+ {
+ return 43;
+ }
+
+ [Kept]
+ public int OnlyCalledViaReflection (int foo, int bar)
+ {
+ return 44;
+ }
+
+ [Kept]
+ public static int OnlyCalledViaReflection (int foo, int bar, int baz)
+ {
+ return 45;
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs b/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs
new file mode 100644
index 000000000..b5b6a1c52
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class MightKeepExtraThings {
+ public static void Main ()
+ {
+ var typeA = typeof (A);
+ var typeB = typeof (B);
+ Console.WriteLine (typeB); // Use typeB so the C# compiler keeps it in the IL code.
+ var method = typeA.GetMethod ("Foo", BindingFlags.Public);
+ method.Invoke (null, new object[] { });
+ }
+
+ [Kept]
+ public class A {
+ [Kept]
+ public int Foo ()
+ {
+ return 42;
+ }
+ }
+
+ [Kept]
+ public class B {
+ [Kept]
+ public int Foo ()
+ {
+ return 43;
+ }
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
new file mode 100644
index 000000000..2dc55aa2c
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
@@ -0,0 +1,40 @@
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class PropertyUsedViaReflection {
+ public static void Main ()
+ {
+ var property = typeof (PropertyUsedViaReflection).GetProperty ("OnlyUsedViaReflection");
+ property.GetValue (null, new object[] { });
+
+ property = typeof (PropertyUsedViaReflection).GetProperty ("SetterOnly");
+ property.SetValue (null, 42, new object[] { });
+
+ property = typeof (PropertyUsedViaReflection).GetProperty ("GetterOnly");
+ property.GetValue (null, new object[] { });
+ }
+
+ [Kept]
+ static int _field;
+
+ [Kept]
+ static int OnlyUsedViaReflection {
+ [Kept]
+ get { return _field; }
+ [Kept]
+ set { _field = value; }
+ }
+
+ [Kept]
+ static int SetterOnly {
+ [Kept]
+ set { _field = value; }
+ }
+
+ [Kept]
+ static int GetterOnly {
+ [Kept]
+ get { return _field; }
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
new file mode 100644
index 000000000..1fcef6673
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
@@ -0,0 +1,161 @@
+using System;
+using System.Diagnostics;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class TypeUsedViaReflection {
+ public static void Main ()
+ {
+ TestNull ();
+ TestEmptyString ();
+ TestFullString ();
+ TestGenericString ();
+ TestFullStringConst();
+ TestTypeAsmName ();
+ TestType ();
+ TestPointer ();
+ TestReference ();
+ TestArray ();
+ TestArrayOfArray ();
+ TestMultiDimensionalArray ();
+ TestMultiDimensionalArrayFullString ();
+ TestMultiDimensionalArrayAsmName ();
+ }
+
+ [Kept]
+ public static void TestNull ()
+ {
+ string reflectionTypeKeptString = null;
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public static void TestEmptyString ()
+ {
+ string reflectionTypeKeptString = "";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class Full { }
+
+ [Kept]
+ public static void TestFullString ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Full, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class Generic<T> { }
+
+ [Kept]
+ public static void TestGenericString ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Generic`1, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class FullConst { }
+
+ [Kept]
+ public static void TestFullStringConst()
+ {
+ const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+FullConst, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var typeKept = Type.GetType(reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class TypeAsmName { }
+
+ [Kept]
+ public static void TestTypeAsmName ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+TypeAsmName, test";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class AType { }
+
+ [Kept]
+ public static void TestType ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+AType";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class Pointer { }
+
+ [Kept]
+ public static void TestPointer ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Pointer*";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class Reference { }
+
+ [Kept]
+ public static void TestReference ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Reference&";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class Array { }
+
+ [Kept]
+ public static void TestArray ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Array[]";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class ArrayOfArray{ }
+
+ [Kept]
+ public static void TestArrayOfArray ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+ArrayOfArray[][]";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+
+ [Kept]
+ public class MultiDimensionalArray{ }
+
+ [Kept]
+ public static void TestMultiDimensionalArray ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArray[,]";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class MultiDimensionalArrayFullString { }
+
+ [Kept]
+ public static void TestMultiDimensionalArrayFullString ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArrayFullString[,], test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+
+ [Kept]
+ public class MultiDimensionalArrayAsmName { }
+
+ [Kept]
+ public static void TestMultiDimensionalArrayAsmName ()
+ {
+ var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArrayAsmName[,], test";
+ var typeKept = Type.GetType (reflectionTypeKeptString, false);
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs
new file mode 100644
index 000000000..1311ac46f
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class TypeUsedViaReflectionAssemblyDoesntExist {
+ public static void Main ()
+ {
+ var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionAssemblyDoesntExist+DoesntExist, test";
+ var typeKept = Type.GetType (typeName, false);
+ }
+
+ public class Full { }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs
new file mode 100644
index 000000000..8df8ee25d
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs
@@ -0,0 +1,23 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.Reflection.Dependencies;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependency.cs" })]
+ [KeptAssembly ("library.dll")]
+ [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency/TypeThatIsUsedViaReflection")]
+ public class TypeUsedViaReflectionInDifferentAssembly {
+ public static void Main ()
+ {
+ AssemblyDependency.UsedToKeepReferenceAtCompileTime ();
+ Helper ();
+ }
+
+ [Kept]
+ static Type Helper ()
+ {
+ return Type.GetType ("Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency+TypeThatIsUsedViaReflection, library");
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs
new file mode 100644
index 000000000..56c1077bf
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs
@@ -0,0 +1,24 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ /// <summary>
+ /// This case we can't detect and need to gracefully do nothing
+ /// </summary>
+ public class TypeUsedViaReflectionLdstrIncomplete {
+ public static void Main ()
+ {
+ var typePart = GetTypePart ();
+ var assemblyPart = ",test";
+ var typeKept = Type.GetType (string.Concat (typePart, assemblyPart), false);
+ }
+
+ public class Full { }
+
+ [Kept]
+ static string GetTypePart ()
+ {
+ return "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionLdstrIncomplete+Full";
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs
new file mode 100644
index 000000000..c4e6b6a38
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs
@@ -0,0 +1,21 @@
+using System;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ /// <summary>
+ /// We don't know if `typeName` will be changed or not. If we error on the side of caution and preserve something
+ /// that we found, I don't think that's a big deal
+ /// </summary>
+ public class TypeUsedViaReflectionLdstrValidButChanged {
+ public static void Main ()
+ {
+ var replace = "Mono.Linker";
+ var with = "Blah.Blah";
+ var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionLdstrValidButChanged+Full, test";
+ var typeKept = Type.GetType (typeName.Replace (replace, with), false);
+ }
+
+ [Kept]
+ public class Full { }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
new file mode 100644
index 000000000..067d08739
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class TypeUsedViaReflectionTypeDoesntExist {
+ public static void Main ()
+ {
+ var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionTypeDoesntExist+Full, DoesntExist";
+ var typeKept = Type.GetType (typeName, false);
+ }
+
+ public class Full { }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs
new file mode 100644
index 000000000..70500994e
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Reflection {
+ public class TypeUsedViaReflectionTypeNameIsSymbol {
+ public static void Main ()
+ {
+ var typeName = "+, test";
+ var typeKept = Type.GetType (typeName, false);
+ }
+
+ public class Full { }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs b/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs
new file mode 100644
index 000000000..e0f7edd79
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.Reflection
+{
+ public class UsedViaReflectionIntegrationTest
+ {
+ public static void Main ()
+ {
+ var test = 42;
+
+ var constructor = typeof (OnlyUsedViaReflection).GetConstructor (BindingFlags.Public, null, new Type [] { }, new ParameterModifier [] { });
+ constructor.Invoke(null, new object[] { });
+
+ if (test == 42) {
+ var method = typeof (OnlyUsedViaReflection).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.NonPublic);
+ method.Invoke (null, new object [] { });
+ }
+ }
+
+ [Kept]
+ private class OnlyUsedViaReflection
+ {
+ [Kept]
+ public OnlyUsedViaReflection ()
+ { }
+
+ [Kept]
+ public OnlyUsedViaReflection (string bar)
+ { }
+
+ private OnlyUsedViaReflection (int foo)
+ { }
+
+ protected OnlyUsedViaReflection (int foo, int bar)
+ { }
+
+ internal OnlyUsedViaReflection (int foo, int bar, int baz)
+ { }
+
+ [Kept]
+ private static int OnlyCalledViaReflection ()
+ {
+ return 42;
+ }
+
+ private int OnlyCalledViaReflection (int foo)
+ {
+ return 43;
+ }
+
+ public int OnlyCalledViaReflection (int foo, int bar)
+ {
+ return 44;
+ }
+
+ public static int OnlyCalledViaReflection (int foo, int bar, int baz)
+ {
+ return 45;
+ }
+ }
+ }
+}