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