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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
// - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
[SkipKeptItemsValidation]
class AssemblyQualifiedNameDataflow
{
static void Main ()
{
TestPublicParameterlessConstructor ();
TestPublicConstructors ();
TestConstructors ();
TestUnqualifiedTypeNameWarns ();
}
[UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
[UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequireNonPublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
static void TestPublicParameterlessConstructor ()
{
string type = GetTypeWithPublicParameterlessConstructor ().AssemblyQualifiedName;
RequirePublicParameterlessConstructor (type);
RequirePublicConstructors (type);
RequireNonPublicConstructors (type);
RequireNothing (type);
}
[UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequireNonPublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
static void TestPublicConstructors ()
{
string type = GetTypeWithPublicConstructors ().AssemblyQualifiedName;
RequirePublicParameterlessConstructor (type);
RequirePublicConstructors (type);
RequireNonPublicConstructors (type);
RequireNothing (type);
}
[UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (string) }, messageCode: "IL2072")]
[UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
static void TestConstructors ()
{
string type = GetTypeWithNonPublicConstructors ().AssemblyQualifiedName;
RequirePublicParameterlessConstructor (type);
RequirePublicConstructors (type);
RequireNonPublicConstructors (type);
RequireNothing (type);
}
[ExpectedWarning ("IL2105",
"Type 'System.Invalid.TypeName' was not found in the caller assembly nor in the base library. " +
"Type name strings used for dynamically accessing a type should be assembly qualified.")]
static void TestUnqualifiedTypeNameWarns ()
{
RequirePublicConstructors ("System.Invalid.TypeName");
}
private static void RequirePublicParameterlessConstructor (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
string type)
{
}
private static void RequirePublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
string type)
{
}
private static void RequireNonPublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
string type)
{
}
private static void RequireNothing (string type)
{
}
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
private static Type GetTypeWithPublicParameterlessConstructor ()
{
return null;
}
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
private static Type GetTypeWithPublicConstructors ()
{
return null;
}
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
private static Type GetTypeWithNonPublicConstructors ()
{
return null;
}
}
}
|