1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
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 ()
{
TestWithBindingFlags ();
TestNullType ();
TestDataFlowType ();
}
[RecognizedReflectionAccessPattern (
typeof (Type), nameof (Type.GetConstructor), new Type [] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier []) },
typeof (OnlyUsedViaReflection), ".ctor", new Type [0])]
[Kept]
static void TestWithBindingFlags ()
{
var constructor = typeof (OnlyUsedViaReflection).GetConstructor (BindingFlags.Public, GetNullValue ("some argument", 2, 3), new Type [] { }, new ParameterModifier [] { });
constructor.Invoke (null, new object [] { });
}
[UnrecognizedReflectionAccessPattern (
typeof (Type), nameof (Type.GetConstructor), new Type [] { typeof (Type []) })]
[Kept]
static void TestNullType ()
{
Type type = null;
var constructor = type.GetConstructor (new Type [] { });
}
[Kept]
static Type FindType ()
{
return null;
}
[UnrecognizedReflectionAccessPattern (
typeof (Type), nameof (Type.GetConstructor), new Type [] { typeof (Type []) })]
[Kept]
static void TestDataFlowType ()
{
Type type = FindType ();
var constructor = type.GetConstructor (new Type [] { });
}
[Kept]
static Binder GetNullValue (string str, int i, long g)
{
return null;
}
[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)
{ }
}
}
}
|