[mcs] C# 7 tuple (foundation only).
[mono.git] / mcs / tests / dtest-001.cs
1 //
2 // dynamic type attribute decoration
3 //
4
5 using System;
6 using System.Collections;
7 using System.Runtime.CompilerServices;
8 using System.Collections.Generic;
9 using System.Linq;
10
11 interface I<T>
12 {
13 }
14
15 class B<T>
16 {
17 }
18
19 class C : B<dynamic>
20 {
21         public C (dynamic d)
22         {
23         }
24
25         public dynamic a;
26         public const dynamic c = default (dynamic);
27
28         public dynamic Prop { set; get; }
29         public dynamic Prop2 { set { } }
30
31         public dynamic this[dynamic d] { set { } get { return 1; } }
32
33         public dynamic Method (dynamic d)
34         {
35                 return null;
36         }
37
38         // Transformation handling required
39         public dynamic[] t;
40         public dynamic[,] t2;
41         public Func<dynamic, int, dynamic[]> v;
42         public I<dynamic>[] iface;
43         public Action<int[], object, dynamic> d2;
44 }
45
46 delegate dynamic Del (dynamic d);
47
48 class Test
49 {
50         public static int Main ()
51         {
52                 Type t = typeof (C);
53                 Type ca = typeof (System.Runtime.CompilerServices.DynamicAttribute);
54
55                 if (t.GetMember ("a")[0].GetCustomAttributes (ca, false).Length != 1)
56                         return 1;
57
58                 if (t.GetMember ("c")[0].GetCustomAttributes (ca, false).Length != 1)
59                         return 3;
60
61                 if (t.GetMember ("Prop")[0].GetCustomAttributes (ca, false).Length != 1)
62                         return 4;
63
64                 if (t.GetMember ("get_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
65                         return 5;
66
67                 if (t.GetMethod ("get_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
68                         return 6;
69
70                 if (t.GetMember ("set_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
71                         return 7;
72
73                 if (t.GetMethod ("set_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
74                         return 8;
75
76                 if (t.GetMethod ("set_Prop").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
77                         return 9;
78
79                 if (t.GetMember ("Prop2")[0].GetCustomAttributes (ca, false).Length != 1)
80                         return 10;
81
82                 if (t.GetMember ("set_Prop2")[0].GetCustomAttributes (ca, false).Length != 0)
83                         return 11;
84
85                 if (t.GetMember ("Item")[0].GetCustomAttributes (ca, false).Length != 1)
86                         return 12;
87
88                 if (t.GetMethod ("get_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
89                         return 13;
90
91                 if (t.GetMethod ("get_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
92                         return 14;
93
94                 if (t.GetMethod ("set_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
95                         return 15;
96
97                 if (t.GetMethod ("set_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
98                         return 16;
99
100                 if (t.GetMethod ("set_Item").GetParameters ()[1].GetCustomAttributes (ca, false).Length != 1)
101                         return 17;
102
103                 if (t.GetMember ("Method")[0].GetCustomAttributes (ca, false).Length != 0)
104                         return 18;
105
106                 if (t.GetMethod ("Method").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
107                         return 19;
108
109                 if (t.GetConstructors ()[0].GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
110                         return 20;
111
112                 if (t.GetConstructors ()[0].GetCustomAttributes (ca, false).Length != 0)
113                         return 21;
114
115                 if (t.GetCustomAttributes (ca, false).Length != 1)
116                         return 22;
117
118                 // Transformations
119                 DynamicAttribute da;
120                 da = t.GetMember ("t")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
121                 if (da == null)
122                         return 40;
123
124                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
125                         return 41;
126
127                 da = t.GetMember ("t2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
128                 if (da == null)
129                         return 42;
130
131                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
132                         return 43;
133
134                 da = t.GetMember ("v")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
135                 if (da == null)
136                         return 44;
137                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true, false, false, true }))
138                         return 45;
139                 
140                 da = t.GetMember ("iface")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
141                 if (da == null)
142                         return 46;
143                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, false, true }))
144                         return 47;
145
146                 da = t.GetMember ("d2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
147                 if (da == null)
148                         return 48;
149                 if (!da.TransformFlags.SequenceEqual (new bool[] { false, false, false, false, true }))
150                         return 49;
151
152                 t = typeof (Del);
153
154                 if (t.GetMember ("Invoke")[0].GetCustomAttributes (ca, false).Length != 0)
155                         return 100;
156
157                 if (t.GetMethod ("Invoke").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
158                         return 101;
159
160                 if (t.GetMethod ("Invoke").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
161                         return 102;
162
163                 Console.WriteLine ("ok");
164                 return 0;
165         }
166 }