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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[SkipKeptItemsValidation]
public class TypeBaseTypeDataFlow
{
public static void Main ()
{
TestAllPropagated (typeof (TestType));
TestPublicConstructorsAreNotPropagated (typeof (TestType));
TestPublicEventsPropagated (typeof (TestType));
TestPublicFieldsPropagated (typeof (TestType));
TestPublicMethodsPropagated (typeof (TestType));
TestPublicNestedTypesAreNotPropagated (typeof (TestType));
TestPublicParameterlessConstructorIsNotPropagated (typeof (TestType));
TestPublicPropertiesPropagated (typeof (TestType));
TestNonPublicConstructorsAreNotPropagated (typeof (TestType));
TestNonPublicEventsAreNotPropagated (typeof (TestType));
TestNonPublicFieldsAreNotPropagated (typeof (TestType));
TestNonPublicMethodsAreNotPropagated (typeof (TestType));
TestNonPublicNestedTypesAreNotPropagated (typeof (TestType));
TestNonPublicPropertiesAreNotPropagated (typeof (TestType));
TestCombinationOfPublicsIsPropagated (typeof (TestType));
TestCombinationOfNonPublicsIsNotPropagated (typeof (TestType));
TestCombinationOfPublicAndNonPublicsPropagatesPublicOnly (typeof (TestType));
TestNoAnnotation (typeof (TestType));
TestAnnotatedAndUnannotated (typeof (TestType), typeof (TestType), 0);
TestNull ();
Mixed_Derived.Test (typeof (TestType), 0);
}
[RecognizedReflectionAccessPattern]
static void TestAllPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type derivedType)
{
derivedType.BaseType.RequiresAll ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) })]
static void TestPublicConstructorsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type derivedType)
{
derivedType.BaseType.RequiresPublicConstructors ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicEvents), new Type[] { typeof (Type) })]
static void TestPublicEventsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] Type derivedType)
{
derivedType.BaseType.RequiresPublicEvents ();
// Should warn
derivedType.BaseType.RequiresPublicMethods ();
// Should warn
derivedType.BaseType.RequiresNonPublicEvents ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicFields), new Type[] { typeof (Type) })]
static void TestPublicFieldsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type derivedType)
{
derivedType.BaseType.RequiresPublicFields ();
// Should warn
derivedType.BaseType.RequiresPublicMethods ();
// Should warn
derivedType.BaseType.RequiresNonPublicFields ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicProperties), new Type[] { typeof (Type) })]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
static void TestPublicMethodsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type derivedType)
{
derivedType.BaseType.RequiresPublicMethods ();
// Should warn
derivedType.BaseType.RequiresPublicProperties ();
// Should warn
derivedType.BaseType.RequiresNonPublicMethods ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicNestedTypes), new Type[] { typeof (Type) })]
static void TestPublicNestedTypesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type derivedType)
{
derivedType.BaseType.RequiresPublicNestedTypes ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor), new Type[] { typeof (Type) })]
static void TestPublicParameterlessConstructorIsNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type derivedType)
{
derivedType.BaseType.RequiresPublicParameterlessConstructor ();
}
[RecognizedReflectionAccessPattern]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
static void TestPublicPropertiesPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresPublicProperties ();
// Should warn
derivedType.BaseType.RequiresPublicMethods ();
// Should warn
derivedType.BaseType.RequiresNonPublicProperties ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) })]
static void TestNonPublicConstructorsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicConstructors ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicEvents), new Type[] { typeof (Type) })]
static void TestNonPublicEventsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicEvents)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicEvents ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicFields), new Type[] { typeof (Type) })]
static void TestNonPublicFieldsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicFields)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicFields ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
static void TestNonPublicMethodsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicMethods ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicNestedTypes), new Type[] { typeof (Type) })]
static void TestNonPublicNestedTypesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicNestedTypes ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
static void TestNonPublicPropertiesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicProperties ();
}
[RecognizedReflectionAccessPattern]
static void TestCombinationOfPublicsIsPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresPublicMethods ();
derivedType.BaseType.RequiresPublicProperties ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
static void TestCombinationOfNonPublicsIsNotPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicMethods ();
derivedType.BaseType.RequiresNonPublicProperties ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
static void TestCombinationOfPublicAndNonPublicsPropagatesPublicOnly (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicMethods ();
derivedType.BaseType.RequiresPublicProperties ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
static void TestNoAnnotation (Type derivedType)
{
derivedType.BaseType.RequiresPublicMethods ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
static void TestAnnotatedAndUnannotated (
Type derivedTypeOne,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type derivedTypeTwo,
int number)
{
Type type = number > 0 ? derivedTypeOne : derivedTypeTwo;
type.BaseType.RequiresPublicMethods ();
}
[UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
static void TestNull ()
{
Type type = null;
type.BaseType.RequiresPublicMethods ();
}
class Mixed_Base
{
public static void PublicMethod () { }
private static void PrivateMethod () { }
}
class Mixed_Derived : Mixed_Base
{
[RecognizedReflectionAccessPattern]
public static void Test (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type typeWithPublicMethods,
int number)
{
Type type;
switch (number) {
case 0:
type = typeof (TestType);
break;
case 1:
type = typeof (Mixed_Derived);
break;
case 2:
type = typeWithPublicMethods;
break;
default:
type = null;
break;
}
type.BaseType.RequiresPublicMethods ();
}
}
class TestType
{
}
}
}
|