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

AttributeUsedByAttributeIsKept.cs « OnlyKeepUsed « Attributes « Mono.Linker.Tests.Cases « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c7c0d292b93980050c4e1b67c752242f34e2841 (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
using System;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed {
	[SetupLinkerArgument ("--used-attrs-only", "true")]
	class AttributeUsedByAttributeIsKept {
		static void Main ()
		{
			var jar = new Jar ();
			jar.SomeMethod ();
		}

		[Foo]
		[Bar]
		[Kar]
		[NotUsed]
		[Kept]
		[KeptMember (".ctor()")]
		[KeptAttributeAttribute (typeof(FooAttribute))]
		[KeptAttributeAttribute (typeof(BarAttribute))]
		[KeptAttributeAttribute (typeof(KarAttribute))]
		class Jar {
			[Kept]
			public void SomeMethod ()
			{
				var attr = typeof (Jar).GetCustomAttributes (typeof (FooAttribute), false) [0];
				var asFooAttr = (FooAttribute) attr;
				asFooAttr.MethodWeWillCall ();
			}
		}

		[Kept]
		[KeptBaseType (typeof(Attribute))]
		class FooAttribute : Attribute {
			[Kept]
			public FooAttribute ()
			{
				// This ctor should be marked lazy.  So let's use another attribute type here which should then trigger that attribute
				// to be marked
				var str = typeof (BarAttribute).ToString ();
				MethodsUsedFromLateMarking.Method1 ();
			}

			[Foo]
			[Bar]
			[Kar]
			[NotUsed]
			[Kept]
			[KeptAttributeAttribute (typeof (FooAttribute))]
			[KeptAttributeAttribute (typeof (BarAttribute))]
			[KeptAttributeAttribute (typeof (KarAttribute))]
			public void MethodWeWillCall ()
			{
			}
		}

		[Kept]
		[KeptBaseType (typeof(Attribute))]
		class BarAttribute : Attribute {
			[Kept]
			public BarAttribute ()
			{
				// Let's do this one more time to make sure we catch everything
				var str = typeof (KarAttribute).ToString ();
				MethodsUsedFromLateMarking.Method2 ();
			}
		}

		[Kept]
		[KeptBaseType (typeof (Attribute))]
		class KarAttribute : Attribute {
			[Kept]
			public KarAttribute ()
			{
				MethodsUsedFromLateMarking.Method3 ();
			}
		}

		class NotUsedAttribute : Attribute {
		}

		[Kept]
		static class MethodsUsedFromLateMarking {
			[Kept]
			public static void Method1 ()
			{
			}

			[Kept]
			public static void Method2 ()
			{
			}

			[Kept]
			public static void Method3 ()
			{
			}
		}

	}
}