2 // Copyright (C) 2010 Novell Inc. http://novell.com
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
24 using System.Collections;
25 using System.Collections.Generic;
26 using System.ComponentModel;
28 using System.Reflection;
29 using System.Windows.Markup;
31 using System.Xaml.Schema;
33 namespace MonoTests.System.Xaml
35 public class ArgumentAttributed
37 public ArgumentAttributed (string s1, string s2)
43 [ConstructorArgument ("s1")]
44 public string Arg1 { get; set; }
46 [ConstructorArgument ("s2")]
47 public string Arg2 { get; set; }
50 public class ComplexPositionalParameterWrapper
52 public ComplexPositionalParameterWrapper ()
56 public ComplexPositionalParameterClass Param { get; set; }
59 public class ComplexPositionalParameterClass : MarkupExtension
61 public ComplexPositionalParameterClass (ComplexPositionalParameterValue value)
66 [ConstructorArgument ("value")]
67 public ComplexPositionalParameterValue Value { get; private set; }
69 public override object ProvideValue (IServiceProvider sp)
75 public class ComplexPositionalParameterValue
77 public string Foo { get; set; }
80 //[MarkupExtensionReturnType (typeof (Array))]
81 //[ContentProperty ("Items")] ... so, these attributes do not affect XamlObjectReader.
82 public class MyArrayExtension : MarkupExtension
84 public MyArrayExtension ()
86 items = new ArrayList ();
89 public MyArrayExtension (Array array)
91 items = new ArrayList (array);
92 this.Type = array.GetType ().GetElementType ();
95 public MyArrayExtension (Type type)
103 get { return items; }
104 private set { items = value; }
107 [ConstructorArgument ("type")]
108 public Type Type { get; set; }
110 public override object ProvideValue (IServiceProvider serviceProvider)
113 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
115 Array a = Array.CreateInstance (Type, Items.Count);
121 // The trailing "A" gives significant difference in XML output!
122 public class MyArrayExtensionA : MarkupExtension
124 public MyArrayExtensionA ()
126 items = new ArrayList ();
129 public MyArrayExtensionA (Array array)
131 items = new ArrayList (array);
132 this.Type = array.GetType ().GetElementType ();
135 public MyArrayExtensionA (Type type)
143 get { return items; }
144 private set { items = value; }
147 [ConstructorArgument ("type")]
148 public Type Type { get; set; }
150 public override object ProvideValue (IServiceProvider serviceProvider)
153 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
155 Array a = Array.CreateInstance (Type, Items.Count);
165 public class TestClass3
167 public TestClass3 Nested { get; set; }
170 public class TestClass4
172 public string Foo { get; set; }
173 public string Bar { get; set; }
176 public class TestClass5
178 public static string Foo { get; set; }
179 public string Bar { get; set; }
180 public string Baz { internal get; set; }
181 public string ReadOnly {
186 public class MyExtension : MarkupExtension
188 public MyExtension ()
192 public MyExtension (Type arg1, string arg2, string arg3)
199 [ConstructorArgument ("arg1")]
200 public Type Foo { get; set; }
202 [ConstructorArgument ("arg2")]
203 public string Bar { get; set; }
205 [ConstructorArgument ("arg3")]
206 public string Baz { get; set; }
208 public override object ProvideValue (IServiceProvider provider)
210 return "provided_value";
214 [TypeConverter (typeof (StringConverter))] // This attribute is the markable difference between MyExtension and this type.
215 public class MyExtension2 : MarkupExtension
217 public MyExtension2 ()
221 public MyExtension2 (Type arg1, string arg2)
227 [ConstructorArgument ("arg1")]
228 public Type Foo { get; set; }
230 [ConstructorArgument ("arg2")]
231 public string Bar { get; set; }
233 public override object ProvideValue (IServiceProvider provider)
235 return "provided_value";
239 [TypeConverter (typeof (StringConverter))] // same as MyExtension2 except that it is *not* MarkupExtension.
240 public class MyExtension3
242 public MyExtension3 ()
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)
253 [ConstructorArgument ("arg1")]
254 public Type Foo { get; set; }
256 [ConstructorArgument ("arg2")]
257 public string Bar { get; set; }
260 [TypeConverter (typeof (DateTimeConverter))] // same as MyExtension3 except for the type converter.
261 public class MyExtension4
263 public MyExtension4 ()
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)
274 [ConstructorArgument ("arg1")]
275 public Type Foo { get; set; }
277 [ConstructorArgument ("arg2")]
278 public string Bar { get; set; }
281 // no type converter, and there are only simple-type arguments == _PositionalParameters is applicable.
282 public class MyExtension5 : MarkupExtension
284 public MyExtension5 (string arg1, string arg2)
290 [ConstructorArgument ("arg1")]
291 public string Foo { get; set; }
293 [ConstructorArgument ("arg2")]
294 public string Bar { get; set; }
296 public override object ProvideValue (IServiceProvider sp)
302 // Almost the same as MyExtension5, BUT there is default constructor which XamlObjectReader prefers.
303 public class MyExtension6 : MarkupExtension
305 public MyExtension6 ()
309 public MyExtension6 (string arg1)
314 [ConstructorArgument ("arg1")]
315 public string Foo { get; set; }
317 public override object ProvideValue (IServiceProvider sp)
323 public class PositionalParametersClass1 : MarkupExtension
325 public PositionalParametersClass1 (string foo)
330 public PositionalParametersClass1 (string foo, int bar)
336 [ConstructorArgument ("foo")]
337 public string Foo { get; set; }
339 [ConstructorArgument ("bar")]
340 public int Bar { get; set; }
342 public override object ProvideValue (IServiceProvider sp)
348 public class PositionalParametersWrapper
350 public PositionalParametersClass1 Body { get; set; }
352 public PositionalParametersWrapper ()
356 public PositionalParametersWrapper (string foo, int bar)
358 Body = new PositionalParametersClass1 (foo, bar);
362 public class ListWrapper
364 public ListWrapper ()
366 Items = new List<int> ();
369 public ListWrapper (List<int> items)
374 public List<int> Items { get; private set; }
377 public class ListWrapper2
379 public ListWrapper2 ()
381 Items = new List<int> ();
384 public ListWrapper2 (List<int> items)
389 public List<int> Items { get; set; } // it is settable, which makes difference.
392 [ContentProperty ("Content")]
393 public class ContentIncludedClass
395 public string Content { get; set; }