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

ObjectGetTypeLibraryMode.cs « Reflection « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 131d1ab87c1f9d598aee2c6206575c279a7d1cdf (plain)
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
// 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.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Reflection
{
	[SetupLinkerArgument ("-a", "test.exe", "library")]
	[ExpectedNoWarnings]
	[KeptMember (".ctor()")]
	public class ObjectGetTypeLibraryMode
	{
		public static void Main ()
		{
			BasicAnnotationWithNoDerivedClasses.Test ();
			BasicNoAnnotationWithNoDerivedClasses.Test ();
		}

		[Kept]
		class BasicAnnotationWithNoDerivedClasses
		{
			[Kept]
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
			public interface IBasicAnnotatedInterface
			{
			}

			[Kept]
			[KeptMember (".ctor()")]
			[KeptInterface (typeof (IBasicAnnotatedInterface))]
			class ClassImplementingAnnotatedInterface : IBasicAnnotatedInterface
			{
				[Kept]
				public void UsedMethod () { }
				[Kept] // The type is not sealed, so trimmer will apply the annotation from the interface
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestInterface ()
			{
				var classImplementingInterface = new ClassImplementingAnnotatedInterface ();
			}

			[Kept]
			[KeptMember (".ctor()")]
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
			class BasicAnnotatedClass
			{
				[Kept]
				public void UsedMethod () { }
				[Kept] // The type is not sealed, so trimmer will apply the annotation from the interface
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestClass ()
			{
				var instance = new BasicAnnotatedClass ();
			}

			[Kept]
			[KeptMember (".ctor()")]
			[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
			struct BasicAnnotatedStruct
			{
				[Kept]
				public void UsedMethod () { }
				[Kept]
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestStruct ()
			{
				var instance = new BasicAnnotatedStruct ();
			}

			[Kept]
			public static void Test ()
			{
				TestInterface ();
				TestClass ();
				TestStruct ();
			}
		}

		[Kept]
		class BasicNoAnnotationWithNoDerivedClasses
		{
			[Kept]
			public interface IBasicNoAnnotatedInterface
			{
			}

			[Kept]
			[KeptMember (".ctor()")]
			[KeptInterface (typeof (IBasicNoAnnotatedInterface))]
			class ClassImplementingNoAnnotatedInterface : IBasicNoAnnotatedInterface
			{
				public void UsedMethod () { }
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestInterface ()
			{
				var classImplementingInterface = new ClassImplementingNoAnnotatedInterface ();
			}

			[Kept]
			[KeptMember (".ctor()")]
			class BasicNoAnnotatedClass
			{
				public void UsedMethod () { }
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestClass ()
			{
				var instance = new BasicNoAnnotatedClass ();
			}

			[Kept]
			[KeptMember (".ctor()")]
			struct BasicNoAnnotatedStruct
			{
				public void UsedMethod () { }
				public void UnusedMethod () { }
			}

			[Kept]
			static void TestStruct ()
			{
				var instance = new BasicNoAnnotatedStruct ();
			}

			[Kept]
			public static void Test ()
			{
				TestInterface ();
				TestClass ();
				TestStruct ();
			}
		}
	}
}