Add testcase for multiple missing IDs
[mono.git] / mcs / class / System.Xaml / Test / System.Xaml / TestedTypes.cs
1 //
2 // Copyright (C) 2010 Novell Inc. http://novell.com
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 using System;
24 using System.Collections;
25 using System.Collections.Generic;
26 using System.ComponentModel;
27 using System.Linq;
28 using System.Reflection;
29 using System.Windows.Markup;
30 using System.Xaml;
31 using System.Xaml.Schema;
32
33 namespace MonoTests.System.Xaml
34 {
35         public class ArgumentAttributed
36         {
37                 public ArgumentAttributed (string s1, string s2)
38                 {
39                         Arg1 = s1;
40                         Arg2 = s2;
41                 }
42
43                 [ConstructorArgument ("s1")]
44                 public string Arg1 { get; set; }
45
46                 [ConstructorArgument ("s2")]
47                 public string Arg2 { get; set; }
48         }
49
50         public class ComplexPositionalParameterWrapper
51         {
52                 public ComplexPositionalParameterWrapper ()
53                 {
54                 }
55                 
56                 public ComplexPositionalParameterClass Param { get; set; }
57         }
58         
59         public class ComplexPositionalParameterClass : MarkupExtension
60         {
61                 public ComplexPositionalParameterClass (ComplexPositionalParameterValue value)
62                 {
63                         this.Value = value;
64                 }
65
66                 [ConstructorArgument ("value")]
67                 public ComplexPositionalParameterValue Value { get; private set; }
68                 
69                 public override object ProvideValue (IServiceProvider sp)
70                 {
71                         return Value.Foo;
72                 }
73         }
74         
75         public class ComplexPositionalParameterValue
76         {
77                 public string Foo { get; set; }
78         }
79         
80         //[MarkupExtensionReturnType (typeof (Array))]
81         //[ContentProperty ("Items")]  ... so, these attributes do not affect XamlObjectReader.
82         public class MyArrayExtension : MarkupExtension
83         {
84                 public MyArrayExtension ()
85                 {
86                         items = new ArrayList ();
87                 }
88
89                 public MyArrayExtension (Array array)
90                 {
91                         items = new ArrayList (array);
92                         this.Type = array.GetType ().GetElementType ();
93                 }
94                 
95                 public MyArrayExtension (Type type)
96                         : this ()
97                 {
98                         this.Type = type;
99                 }
100
101                 IList items;
102                 public IList Items {
103                         get { return items; }
104                         private set { items = value; }
105                 }
106                 
107                 [ConstructorArgument ("type")]
108                 public Type Type { get; set; }
109                 
110                 public override object ProvideValue (IServiceProvider serviceProvider)
111                 {
112                         if (Type == null)
113                                 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
114
115                         Array a = Array.CreateInstance (Type, Items.Count);
116                         Items.CopyTo (a, 0);
117                         return a;
118                 }
119         }
120
121         // The trailing "A" gives significant difference in XML output!
122         public class MyArrayExtensionA : MarkupExtension
123         {
124                 public MyArrayExtensionA ()
125                 {
126                         items = new ArrayList ();
127                 }
128
129                 public MyArrayExtensionA (Array array)
130                 {
131                         items = new ArrayList (array);
132                         this.Type = array.GetType ().GetElementType ();
133                 }
134                 
135                 public MyArrayExtensionA (Type type)
136                         : this ()
137                 {
138                         this.Type = type;
139                 }
140
141                 IList items;
142                 public IList Items {
143                         get { return items; }
144                         private set { items = value; }
145                 }
146                 
147                 [ConstructorArgument ("type")]
148                 public Type Type { get; set; }
149                 
150                 public override object ProvideValue (IServiceProvider serviceProvider)
151                 {
152                         if (Type == null)
153                                 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
154
155                         Array a = Array.CreateInstance (Type, Items.Count);
156                         Items.CopyTo (a, 0);
157                         return a;
158                 }
159         }
160
161         class TestClass1
162         {
163         }
164
165         public class TestClass3
166         {
167                 public TestClass3 Nested { get; set; }
168         }
169
170         public class TestClass4
171         {
172                 public string Foo { get; set; }
173                 public string Bar { get; set; }
174         }
175         
176         public class TestClass5
177         {
178                 public static string Foo { get; set; }
179                 public string Bar { get; set; }
180                 public string Baz { internal get; set; }
181                 public string ReadOnly {
182                         get { return Foo; }
183                 }
184         }
185
186         public class MyExtension : MarkupExtension
187         {
188                 public MyExtension ()
189                 {
190                 }
191
192                 public MyExtension (Type arg1, string arg2, string arg3)
193                 {
194                         Foo = arg1;
195                         Bar = arg2;
196                         Baz = arg3;
197                 }
198
199                 [ConstructorArgument ("arg1")]
200                 public Type Foo { get; set; }
201                 
202                 [ConstructorArgument ("arg2")]
203                 public string Bar { get; set; }
204                 
205                 [ConstructorArgument ("arg3")]
206                 public string Baz { get; set; }
207
208                 public override object ProvideValue (IServiceProvider provider)
209                 {
210                         return "provided_value";
211                 }
212         }
213
214         [TypeConverter (typeof (StringConverter))] // This attribute is the markable difference between MyExtension and this type.
215         public class MyExtension2 : MarkupExtension
216         {
217                 public MyExtension2 ()
218                 {
219                 }
220
221                 public MyExtension2 (Type arg1, string arg2)
222                 {
223                         Foo = arg1;
224                         Bar = arg2;
225                 }
226
227                 [ConstructorArgument ("arg1")]
228                 public Type Foo { get; set; }
229                 
230                 [ConstructorArgument ("arg2")]
231                 public string Bar { get; set; }
232
233                 public override object ProvideValue (IServiceProvider provider)
234                 {
235                         return "provided_value";
236                 }
237         }
238
239         [TypeConverter (typeof (StringConverter))] // same as MyExtension2 except that it is *not* MarkupExtension.
240         public class MyExtension3
241         {
242                 public MyExtension3 ()
243                 {
244                 }
245
246                 // cf. According to [MS-XAML-2009] 3.2.1.11, constructors are invalid unless the type is derived from TypeExtension. So, it is likely *ignored*.
247                 public MyExtension3 (Type arg1, string arg2)
248                 {
249                         Foo = arg1;
250                         Bar = arg2;
251                 }
252
253                 [ConstructorArgument ("arg1")]
254                 public Type Foo { get; set; }
255                 
256                 [ConstructorArgument ("arg2")]
257                 public string Bar { get; set; }
258         }
259
260         [TypeConverter (typeof (DateTimeConverter))] // same as MyExtension3 except for the type converter.
261         public class MyExtension4
262         {
263                 public MyExtension4 ()
264                 {
265                 }
266
267                 // cf. According to [MS-XAML-2009] 3.2.1.11, constructors are invalid unless the type is derived from TypeExtension. So, it is likely *ignored*.
268                 public MyExtension4 (Type arg1, string arg2)
269                 {
270                         Foo = arg1;
271                         Bar = arg2;
272                 }
273
274                 [ConstructorArgument ("arg1")]
275                 public Type Foo { get; set; }
276                 
277                 [ConstructorArgument ("arg2")]
278                 public string Bar { get; set; }
279         }
280
281         // no type converter, and there are only simple-type arguments == _PositionalParameters is applicable.
282         public class MyExtension5 : MarkupExtension
283         {
284                 public MyExtension5 (string arg1, string arg2)
285                 {
286                         Foo = arg1;
287                         Bar = arg2;
288                 }
289
290                 [ConstructorArgument ("arg1")]
291                 public string Foo { get; set; }
292                 
293                 [ConstructorArgument ("arg2")]
294                 public string Bar { get; set; }
295                 
296                 public override object ProvideValue (IServiceProvider sp)
297                 {
298                         return Foo;
299                 }
300         }
301
302         // Almost the same as MyExtension5, BUT there is default constructor which XamlObjectReader prefers.
303         public class MyExtension6 : MarkupExtension
304         {
305                 public MyExtension6 ()
306                 {
307                 }
308
309                 public MyExtension6 (string arg1)
310                 {
311                         Foo = arg1;
312                 }
313
314                 [ConstructorArgument ("arg1")]
315                 public string Foo { get; set; }
316                 
317                 public override object ProvideValue (IServiceProvider sp)
318                 {
319                         return Foo;
320                 }
321         }
322
323         public class PositionalParametersClass1 : MarkupExtension
324         {
325                 public PositionalParametersClass1 (string foo)
326                         : this (foo, -1)
327                 {
328                 }
329                 
330                 public PositionalParametersClass1 (string foo, int bar)
331                 {
332                         Foo = foo;
333                         Bar = bar;
334                 }
335                 
336                 [ConstructorArgument ("foo")]
337                 public string Foo { get; set; }
338
339                 [ConstructorArgument ("bar")]
340                 public int Bar { get; set; }
341
342                 public override object ProvideValue (IServiceProvider sp)
343                 {
344                         return Foo;
345                 }
346         }
347
348         public class PositionalParametersWrapper
349         {
350                 public PositionalParametersClass1 Body { get; set; }
351                 
352                 public PositionalParametersWrapper ()
353                 {
354                 }
355                 
356                 public PositionalParametersWrapper (string foo, int bar)
357                 {
358                         Body = new PositionalParametersClass1 (foo, bar);
359                 }
360         }
361         
362         public class ListWrapper
363         {
364                 public ListWrapper ()
365                 {
366                         Items = new List<int> ();
367                 }
368
369                 public ListWrapper (List<int> items)
370                 {
371                         Items = items;
372                 }
373
374                 public List<int> Items { get; private set; }
375         }
376         
377         public class ListWrapper2
378         {
379                 public ListWrapper2 ()
380                 {
381                         Items = new List<int> ();
382                 }
383
384                 public ListWrapper2 (List<int> items)
385                 {
386                         Items = items;
387                 }
388
389                 public List<int> Items { get; set; } // it is settable, which makes difference.
390         }
391
392         [ContentProperty ("Content")]
393         public class ContentIncludedClass
394         {
395                 public string Content { get; set; }
396         }
397 }