[metadata] Fix leaks when handling a few attributes (#16675)
[mono-project.git] / mcs / tests / test-tuple-05.cs
blob593885d68c53c7e3ee29d1a7f777147e2f6cbdc2
1 //
2 // tuple names attribute decoration
3 //
5 using System;
6 using System.Collections;
7 using System.Runtime.CompilerServices;
8 using System.Collections.Generic;
9 using System.Linq;
11 interface I<T>
15 class B<T>
19 class C // : B<(int a, int b)> // TODO: I<(a, b)
21 public C((int a, int b) d)
25 public (int a, int b) a;
26 public (int, (int a, int b)) c;
28 public (int a, int b) Prop { set; get; }
29 public (int a, int b) Prop2 { set { } }
31 public (int a, int b)? this[(int a, int b) d] { set { } get { return null; } }
33 public (int a, int b)? Method(ref (int a, int b) d)
35 return null;
38 public (int a, int b)[] t;
39 public (int a, int b)[,] t2;
40 // TODO: public Func<(int a, int b), int, (int c, int d)[]> v;
41 // public I<(int a, int b)>[] iface;
42 // TODO: public Action<(long, (long u, long))[], object, (int a, int b)> d2;
43 public (((int aa1, int aa2) a1, (int, int) a2) x1, ((int cc1, int cc2) b1, (int dd1, int dd2) b2) x2) d3;
46 delegate (int a, int b) Del((int a, int b) d);
48 class Test
50 public static int Main()
52 Type t = typeof(C);
53 Type ca = typeof(TupleElementNamesAttribute);
54 TupleElementNamesAttribute da;
56 if (t.GetMember("a")[0].GetCustomAttributes(ca, false).Length != 1)
57 return 1;
59 if (t.GetMember("c")[0].GetCustomAttributes(ca, false).Length != 1)
60 return 3;
62 if (t.GetMember("Prop")[0].GetCustomAttributes(ca, false).Length != 1)
63 return 4;
65 if (t.GetMember("get_Prop")[0].GetCustomAttributes(ca, false).Length != 0)
66 return 5;
68 if (t.GetMethod("get_Prop").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
69 return 6;
71 if (t.GetMember("set_Prop")[0].GetCustomAttributes(ca, false).Length != 0)
72 return 7;
74 if (t.GetMethod("set_Prop").ReturnParameter.GetCustomAttributes(ca, false).Length != 0)
75 return 8;
77 if (t.GetMethod("set_Prop").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
78 return 9;
80 if (t.GetMember("Prop2")[0].GetCustomAttributes(ca, false).Length != 1)
81 return 10;
83 if (t.GetMember("set_Prop2")[0].GetCustomAttributes(ca, false).Length != 0)
84 return 11;
86 if (t.GetMember("Item")[0].GetCustomAttributes(ca, false).Length != 1)
87 return 12;
89 if (t.GetMethod("get_Item").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
90 return 13;
92 if (t.GetMethod("get_Item").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
93 return 14;
95 if (t.GetMethod("set_Item").ReturnParameter.GetCustomAttributes(ca, false).Length != 0)
96 return 15;
98 if (t.GetMethod("set_Item").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
99 return 16;
101 if (t.GetMethod("set_Item").GetParameters()[1].GetCustomAttributes(ca, false).Length != 1)
102 return 17;
104 if (t.GetMember("Method")[0].GetCustomAttributes(ca, false).Length != 0)
105 return 18;
107 var res = t.GetMethod("Method").GetParameters()[0].GetCustomAttributes(ca, false);
108 if (res.Length != 1)
109 return 19;
111 da = res[0] as TupleElementNamesAttribute;
112 if (da == null)
113 return 190;
114 if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
115 return 191;
117 if (t.GetConstructors()[0].GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
118 return 20;
120 if (t.GetConstructors()[0].GetCustomAttributes(ca, false).Length != 0)
121 return 21;
123 // if (t.GetCustomAttributes(ca, false).Length != 1)
124 // return 22;
126 // Transformations
127 da = t.GetMember("t")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
128 if (da == null)
129 return 40;
131 if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
132 return 41;
134 da = t.GetMember("t2")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
135 if (da == null)
136 return 42;
138 if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
139 return 43;
141 //da = t.GetMember("v")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
142 //if (da == null)
143 // return 44;
145 //if (!da.TransformNames.SequenceEqual(new string[] { "a", "b", "c", "d" }))
146 // return 45;
148 //da = t.GetMember("iface")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
149 //if (da == null)
150 // return 46;
152 //if (!da.TransformNames.SequenceEqual(new string[] { "a", "b" }))
153 // return 47;
155 //da = t.GetMember("d2")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
156 //if (da == null)
157 // return 48;
158 //if (!da.TransformNames.SequenceEqual(new string[] { null, null, "u", null, "a", "b" }))
159 // return 49;
161 da = t.GetMember("d3")[0].GetCustomAttributes(ca, false)[0] as TupleElementNamesAttribute;
162 if (da == null)
163 return 50;
164 if (!da.TransformNames.SequenceEqual(new string[] { "x1", "x2", "a1", "a2", "aa1", "aa2", null, null, "b1", "b2", "cc1", "cc2", "dd1", "dd2" }))
165 return 51;
167 t = typeof(Del);
169 if (t.GetMember("Invoke")[0].GetCustomAttributes(ca, false).Length != 0)
170 return 100;
172 if (t.GetMethod("Invoke").GetParameters()[0].GetCustomAttributes(ca, false).Length != 1)
173 return 101;
175 if (t.GetMethod("Invoke").ReturnParameter.GetCustomAttributes(ca, false).Length != 1)
176 return 102;
178 Console.WriteLine("ok");
179 return 0;