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

ExpressionFieldString.cs « Reflection « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0a6959ce82a5c9ad964aa68806a0315a46efd448 (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
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Reflection
{
	[Reference ("System.Core.dll")]
	public class ExpressionFieldString
	{
		[UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Field),
			new Type[] { typeof (Expression), typeof (Type), typeof (string) }, messageCode: "IL2072")]
		public static void Main ()
		{
			Expression.Field (Expression.Parameter (typeof (int), ""), typeof (ExpressionFieldString), "Field");
			Expression.Field (null, typeof (ExpressionFieldString), "StaticField");
			Expression.Field (null, typeof (Derived), "_protectedFieldOnBase");
			Expression.Field (null, typeof (Derived), "_publicFieldOnBase");
			UnknownType.Test ();
			UnknownString.Test ();
			Expression.Field (null, GetType (), "This string will not be reached"); // UnrecognizedReflectionAccessPattern
		}

		[Kept]
		private int Field;

		[Kept]
		static private int StaticField;

		private int UnusedField;

		[Kept]
		static Type GetType ()
		{
			return typeof (int);
		}

		[Kept]
		class UnknownType
		{
			[Kept]
			public static int Field1;

			[Kept]
			private int Field2;

			[Kept]
			public static void Test ()
			{
				Expression.Field (null, GetType (), "This string will not be reached");
			}

			[Kept]
			[return: KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
			[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)]
			static Type GetType ()
			{
				return typeof (UnknownType);
			}
		}

		[Kept]
		class UnknownString
		{
			[Kept]
			private static int Field1;

			[Kept]
			public int Field2;

			[Kept]
			public static void Test ()
			{
				Expression.Field (null, typeof (UnknownString), GetString ());
			}

			[Kept]
			static string GetString ()
			{
				return "UnknownString";
			}
		}

		[Kept]
		class Base
		{
			[Kept]
			protected static bool _protectedFieldOnBase;

			[Kept]
			public static bool _publicFieldOnBase;
		}

		[Kept]
		[KeptBaseType (typeof (Base))]
		class Derived : Base
		{
		}
	}
}