[build] Fix warning (#4177)
[mono-project.git] / mcs / tests / dtest-001.cs
blobf0b58ef8b9a0758ad265a412d9b0cb85b601ff7a
1 //
2 // dynamic type 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 C
17 public C (dynamic d)
21 public dynamic a;
22 public const dynamic c = default (dynamic);
24 public dynamic Prop { set; get; }
25 public dynamic Prop2 { set { } }
27 public dynamic this[dynamic d] { set { } get { return 1; } }
29 public dynamic Method (dynamic d)
31 return null;
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;
42 delegate dynamic Del (dynamic d);
44 class Test
46 public static int Main ()
48 Type t = typeof (C);
49 Type ca = typeof (System.Runtime.CompilerServices.DynamicAttribute);
51 if (t.GetMember ("a")[0].GetCustomAttributes (ca, false).Length != 1)
52 return 1;
54 if (t.GetMember ("c")[0].GetCustomAttributes (ca, false).Length != 1)
55 return 3;
57 if (t.GetMember ("Prop")[0].GetCustomAttributes (ca, false).Length != 1)
58 return 4;
60 if (t.GetMember ("get_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
61 return 5;
63 if (t.GetMethod ("get_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
64 return 6;
66 if (t.GetMember ("set_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
67 return 7;
69 if (t.GetMethod ("set_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
70 return 8;
72 if (t.GetMethod ("set_Prop").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
73 return 9;
75 if (t.GetMember ("Prop2")[0].GetCustomAttributes (ca, false).Length != 1)
76 return 10;
78 if (t.GetMember ("set_Prop2")[0].GetCustomAttributes (ca, false).Length != 0)
79 return 11;
81 if (t.GetMember ("Item")[0].GetCustomAttributes (ca, false).Length != 1)
82 return 12;
84 if (t.GetMethod ("get_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
85 return 13;
87 if (t.GetMethod ("get_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
88 return 14;
90 if (t.GetMethod ("set_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
91 return 15;
93 if (t.GetMethod ("set_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
94 return 16;
96 if (t.GetMethod ("set_Item").GetParameters ()[1].GetCustomAttributes (ca, false).Length != 1)
97 return 17;
99 if (t.GetMember ("Method")[0].GetCustomAttributes (ca, false).Length != 0)
100 return 18;
102 if (t.GetMethod ("Method").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
103 return 19;
105 if (t.GetConstructors ()[0].GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
106 return 20;
108 if (t.GetConstructors ()[0].GetCustomAttributes (ca, false).Length != 0)
109 return 21;
111 // Transformations
112 DynamicAttribute da;
113 da = t.GetMember ("t")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
114 if (da == null)
115 return 40;
117 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
118 return 41;
120 da = t.GetMember ("t2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
121 if (da == null)
122 return 42;
124 if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
125 return 43;
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;
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;
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;
145 t = typeof (Del);
147 if (t.GetMember ("Invoke")[0].GetCustomAttributes (ca, false).Length != 0)
148 return 100;
150 if (t.GetMethod ("Invoke").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
151 return 101;
153 if (t.GetMethod ("Invoke").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
154 return 102;
156 Console.WriteLine ("ok");
157 return 0;