acf3711be4963bdeacda9fdbfa54d6c737af2199
[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.Diagnostics;
28 using System.Globalization;
29 using System.IO;
30 using System.Linq;
31 using System.Reflection;
32 using System.Windows.Markup;
33 using System.Xaml;
34 using System.Xaml.Schema;
35 using System.Xml;
36 using System.Xml.Schema;
37 using System.Xml.Serialization;
38
39 [assembly: XmlnsDefinition ("http://www.domain.com/path", "XamlTest")] // bug #680385
40 [assembly: XmlnsDefinition ("http://www.domain.com/path", "SecondTest")] // bug #681045, same xmlns key for different clrns.
41
42 namespace MonoTests.System.Xaml
43 {
44         public class ArgumentAttributed
45         {
46                 public ArgumentAttributed (string s1, string s2)
47                 {
48                         Arg1 = s1;
49                         Arg2 = s2;
50                 }
51
52                 [ConstructorArgument ("s1")]
53                 public string Arg1 { get; set; }
54
55                 [ConstructorArgument ("s2")]
56                 public string Arg2 { get; set; }
57         }
58
59         public class ComplexPositionalParameterWrapper
60         {
61                 public ComplexPositionalParameterWrapper ()
62                 {
63                 }
64                 
65                 public ComplexPositionalParameterClass Param { get; set; }
66         }
67         
68         [TypeConverter (typeof (ComplexPositionalParameterClassConverter))]
69         public class ComplexPositionalParameterClass : MarkupExtension
70         {
71                 public ComplexPositionalParameterClass (ComplexPositionalParameterValue value)
72                 {
73                         this.Value = value;
74                 }
75
76                 [ConstructorArgument ("value")]
77                 public ComplexPositionalParameterValue Value { get; private set; }
78                 
79                 public override object ProvideValue (IServiceProvider sp)
80                 {
81                         return Value.Foo;
82                 }
83         }
84         
85         public class ComplexPositionalParameterClassConverter : TypeConverter
86         {
87                 public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
88                 {
89                         return sourceType == typeof (string);
90                 }
91
92                 public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object valueToConvert)
93                 {
94                         return new ComplexPositionalParameterClass (new ComplexPositionalParameterValue () {Foo = (string) valueToConvert});
95                 }
96
97                 public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
98                 {
99                         // conversion to string is not supported.
100                         return destinationType == typeof (ComplexPositionalParameterClass);
101                 }
102         }
103         
104         public class ComplexPositionalParameterValue
105         {
106                 public string Foo { get; set; }
107         }
108         
109         //[MarkupExtensionReturnType (typeof (Array))]
110         //[ContentProperty ("Items")]  ... so, these attributes do not affect XamlObjectReader.
111         public class MyArrayExtension : MarkupExtension
112         {
113                 public MyArrayExtension ()
114                 {
115                         items = new ArrayList ();
116                 }
117
118                 public MyArrayExtension (Array array)
119                 {
120                         items = new ArrayList (array);
121                         this.Type = array.GetType ().GetElementType ();
122                 }
123                 
124                 public MyArrayExtension (Type type)
125                         : this ()
126                 {
127                         this.Type = type;
128                 }
129
130                 IList items;
131                 public IList Items {
132                         get { return items; }
133                         private set { items = value; }
134                 }
135                 
136                 [ConstructorArgument ("type")]
137                 public Type Type { get; set; }
138                 
139                 public override object ProvideValue (IServiceProvider serviceProvider)
140                 {
141                         if (Type == null)
142                                 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
143
144                         Array a = Array.CreateInstance (Type, Items.Count);
145                         Items.CopyTo (a, 0);
146                         return a;
147                 }
148         }
149
150         // The trailing "A" gives significant difference in XML output!
151         public class MyArrayExtensionA : MarkupExtension
152         {
153                 public MyArrayExtensionA ()
154                 {
155                         items = new ArrayList ();
156                 }
157
158                 public MyArrayExtensionA (Array array)
159                 {
160                         items = new ArrayList (array);
161                         this.Type = array.GetType ().GetElementType ();
162                 }
163                 
164                 public MyArrayExtensionA (Type type)
165                         : this ()
166                 {
167                         this.Type = type;
168                 }
169
170                 IList items;
171                 public IList Items {
172                         get { return items; }
173                         private set { items = value; }
174                 }
175                 
176                 [ConstructorArgument ("type")]
177                 public Type Type { get; set; }
178                 
179                 public override object ProvideValue (IServiceProvider serviceProvider)
180                 {
181                         if (Type == null)
182                                 throw new InvalidOperationException ("Type property must be set before calling ProvideValue method");
183
184                         Array a = Array.CreateInstance (Type, Items.Count);
185                         Items.CopyTo (a, 0);
186                         return a;
187                 }
188         }
189
190         class TestClass1
191         {
192         }
193
194         public class TestClass3
195         {
196                 public TestClass3 Nested { get; set; }
197         }
198
199         public class TestClass4
200         {
201                 public string Foo { get; set; }
202                 public string Bar { get; set; }
203         }
204         
205         public class TestClass5
206         {
207                 public static string Foo { get; set; }
208                 public string Bar { get; set; }
209                 public string Baz { internal get; set; }
210                 public string ReadOnly {
211                         get { return Foo; }
212                 }
213         }
214
215         public class MyExtension : MarkupExtension
216         {
217                 public MyExtension ()
218                 {
219                 }
220
221                 public MyExtension (Type arg1, string arg2, string arg3)
222                 {
223                         Foo = arg1;
224                         Bar = arg2;
225                         Baz = arg3;
226                 }
227
228                 [ConstructorArgument ("arg1")]
229                 public Type Foo { get; set; }
230                 
231                 [ConstructorArgument ("arg2")]
232                 public string Bar { get; set; }
233                 
234                 [ConstructorArgument ("arg3")]
235                 public string Baz { get; set; }
236
237                 public override object ProvideValue (IServiceProvider provider)
238                 {
239                         return "provided_value";
240                 }
241         }
242
243         [TypeConverter (typeof (StringConverter))] // This attribute is the markable difference between MyExtension and this type.
244         public class MyExtension2 : MarkupExtension
245         {
246                 public MyExtension2 ()
247                 {
248                 }
249
250                 public MyExtension2 (Type arg1, string arg2)
251                 {
252                         Foo = arg1;
253                         Bar = arg2;
254                 }
255
256                 [ConstructorArgument ("arg1")]
257                 public Type Foo { get; set; }
258                 
259                 [ConstructorArgument ("arg2")]
260                 public string Bar { get; set; }
261
262                 public override object ProvideValue (IServiceProvider provider)
263                 {
264                         return "provided_value";
265                 }
266         }
267
268         [TypeConverter (typeof (StringConverter))] // same as MyExtension2 except that it is *not* MarkupExtension.
269         public class MyExtension3
270         {
271                 public MyExtension3 ()
272                 {
273                 }
274
275                 // 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*.
276                 public MyExtension3 (Type arg1, string arg2)
277                 {
278                         Foo = arg1;
279                         Bar = arg2;
280                 }
281
282                 [ConstructorArgument ("arg1")]
283                 public Type Foo { get; set; }
284                 
285                 [ConstructorArgument ("arg2")]
286                 public string Bar { get; set; }
287         }
288
289         [TypeConverter (typeof (DateTimeConverter))] // same as MyExtension3 except for the type converter.
290         public class MyExtension4
291         {
292                 public MyExtension4 ()
293                 {
294                 }
295
296                 // 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*.
297                 public MyExtension4 (Type arg1, string arg2)
298                 {
299                         Foo = arg1;
300                         Bar = arg2;
301                 }
302
303                 [ConstructorArgument ("arg1")]
304                 public Type Foo { get; set; }
305                 
306                 [ConstructorArgument ("arg2")]
307                 public string Bar { get; set; }
308         }
309
310         // no type converter, and there are only simple-type arguments == _PositionalParameters is applicable.
311         public class MyExtension5 : MarkupExtension
312         {
313                 public MyExtension5 (string arg1, string arg2)
314                 {
315                         Foo = arg1;
316                         Bar = arg2;
317                 }
318
319                 [ConstructorArgument ("arg1")]
320                 public string Foo { get; set; }
321                 
322                 [ConstructorArgument ("arg2")]
323                 public string Bar { get; set; }
324                 
325                 public override object ProvideValue (IServiceProvider sp)
326                 {
327                         return Foo;
328                 }
329         }
330
331         // Almost the same as MyExtension5, BUT there is default constructor which XamlObjectReader prefers.
332         public class MyExtension6 : MarkupExtension
333         {
334                 public MyExtension6 ()
335                 {
336                 }
337
338                 public MyExtension6 (string arg1)
339                 {
340                         Foo = arg1;
341                 }
342
343                 [ConstructorArgument ("arg1")]
344                 public string Foo { get; set; }
345                 
346                 public override object ProvideValue (IServiceProvider sp)
347                 {
348                         return Foo;
349                 }
350         }
351
352         public class PositionalParametersClass1 : MarkupExtension
353         {
354                 public PositionalParametersClass1 (string foo)
355                         : this (foo, -1)
356                 {
357                 }
358                 
359                 public PositionalParametersClass1 (string foo, int bar)
360                 {
361                         Foo = foo;
362                         Bar = bar;
363                 }
364                 
365                 [ConstructorArgument ("foo")]
366                 public string Foo { get; set; }
367
368                 [ConstructorArgument ("bar")]
369                 public int Bar { get; set; }
370
371                 public override object ProvideValue (IServiceProvider sp)
372                 {
373                         return Foo;
374                 }
375         }
376
377         public class PositionalParametersWrapper
378         {
379                 public PositionalParametersClass1 Body { get; set; }
380                 
381                 public PositionalParametersWrapper ()
382                 {
383                 }
384                 
385                 public PositionalParametersWrapper (string foo, int bar)
386                 {
387                         Body = new PositionalParametersClass1 (foo, bar);
388                 }
389         }
390         
391         public class ListWrapper
392         {
393                 public ListWrapper ()
394                 {
395                         Items = new List<int> ();
396                 }
397
398                 public ListWrapper (List<int> items)
399                 {
400                         Items = items;
401                 }
402
403                 public List<int> Items { get; private set; }
404         }
405         
406         public class ListWrapper2
407         {
408                 public ListWrapper2 ()
409                 {
410                         Items = new List<int> ();
411                 }
412
413                 public ListWrapper2 (List<int> items)
414                 {
415                         Items = items;
416                 }
417
418                 public List<int> Items { get; set; } // it is settable, which makes difference.
419         }
420
421         [ContentProperty ("Content")]
422         public class ContentIncludedClass
423         {
424                 public string Content { get; set; }
425         }
426
427         public class StaticClass1
428         {
429                 static StaticClass1 ()
430                 {
431                         FooBar = "test";
432                 }
433
434                 public static string FooBar { get; set; }
435         }
436
437         public class StaticExtensionWrapper
438         {
439                 public StaticExtensionWrapper ()
440                 {
441                 }
442                 
443                 public StaticExtension Param { get; set; }
444
445                 public static string Foo = "foo";
446         }
447         
448         public class TypeExtensionWrapper
449         {
450                 public TypeExtensionWrapper ()
451                 {
452                 }
453                 
454                 public TypeExtension Param { get; set; }
455         }
456         
457         public class XDataWrapper
458         {
459                 public XData Markup { get; set; }
460         }
461         
462         // FIXME: test it with XamlXmlReader (needs to create xml first)
463         public class EventContainer
464         {
465                 public event Action Run;
466         }
467         
468         public class NamedItem
469         {
470                 public NamedItem ()
471                 {
472                         References = new List<NamedItem> ();
473                 }
474                 
475                 public NamedItem (string name)
476                         : this ()
477                 {
478                         ItemName = name;
479                 }
480                 
481                 public string ItemName { get; set; }
482                 public IList<NamedItem> References { get; private set; }
483         }
484         
485         [RuntimeNameProperty ("ItemName")]
486         public class NamedItem2
487         {
488                 public NamedItem2 ()
489                 {
490                         References = new List<NamedItem2> ();
491                 }
492                 
493                 public NamedItem2 (string name)
494                         : this ()
495                 {
496                         ItemName = name;
497                 }
498                 
499                 public string ItemName { get; set; }
500                 public IList<NamedItem2> References { get; private set; }
501         }
502
503         [TypeConverter (typeof (TestValueConverter))]
504         public class TestValueSerialized
505         {
506                 public TestValueSerialized ()
507                 {
508                 }
509
510                 public string Foo { get; set; }
511         }
512
513         public class TestValueConverter : TypeConverter
514         {
515                 public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
516                 {
517                         //Console.Error.WriteLine ("### {0}:{1}", sourceType, context);
518                         ValueSerializerContextTest.Context = (IValueSerializerContext) context;
519                         return true;
520                 }
521                 
522                 public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object source)
523                 {
524                         //Console.Error.WriteLine ("##### {0}:{1}", source, context);
525                         ValueSerializerContextTest.Provider = (IServiceProvider) context;
526                         var sp = context as IServiceProvider;
527                         // ValueSerializerContextTest.Context = (IValueSerializerContext) context; -> causes InvalidCastException
528                         if ((source as string) == "v")
529                                 return new TestValueSerialized ();
530                         throw new Exception ("huh");
531                 }
532
533                 public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
534                 {
535                         //Console.Error.WriteLine ("$$$ {0}:{1}", destinationType, context);
536                         ValueSerializerContextTest.Context = (IValueSerializerContext) context;
537                         return destinationType != typeof (MarkupExtension);
538                 }
539         }
540
541         [ContentProperty ("Value")]
542         public class XmlSerializableWrapper
543         {
544                 public XmlSerializableWrapper () // mandatory
545                         : this (new XmlSerializable ())
546                 {
547                 }
548
549                 public XmlSerializableWrapper (XmlSerializable val)
550                 {
551                         this.val = val;
552                 }
553
554                 XmlSerializable val;
555
556                 public XmlSerializable Value {
557                         get { return val; }
558                         // To make it become XData, it cannot have a setter.
559                 }
560         }
561
562         public class XmlSerializable : IXmlSerializable
563         {
564                 public XmlSerializable ()
565                 {
566                 }
567
568                 public XmlSerializable (string raw)
569                 {
570                         this.raw = raw;
571                 }
572
573                 string raw;
574
575                 public string GetRaw ()
576                 {
577                         return raw;
578                 }
579
580                 public void ReadXml (XmlReader reader)
581                 {
582                         reader.MoveToContent ();
583                         raw = reader.ReadOuterXml ();
584                 }
585                 
586                 public void WriteXml (XmlWriter writer)
587                 {
588                         if (raw != null) {
589                                 var xr = XmlReader.Create (new StringReader (raw));
590                                 while (!xr.EOF)
591                                         writer.WriteNode (xr, false);
592                         }
593                 }
594                 
595                 public XmlSchema GetSchema ()
596                 {
597                         return null;
598                 }
599         }
600         
601         public class Attachable
602         {
603                 public static readonly AttachableMemberIdentifier FooIdentifier = new AttachableMemberIdentifier (typeof (Attachable), "Foo");
604                 public static readonly AttachableMemberIdentifier ProtectedIdentifier = new AttachableMemberIdentifier (typeof (Attachable), "Protected");
605                 
606                 public static string GetFoo (object target)
607                 {
608                         string v;
609                         return AttachablePropertyServices.TryGetProperty (target, FooIdentifier, out v) ? v : null;
610                 }
611                 
612                 public static void SetFoo (object target, string value)
613                 {
614                         AttachablePropertyServices.SetProperty (target, FooIdentifier, value);
615                 }
616
617                 public static string GetBar (object target, object signatureMismatch)
618                 {
619                         return null;
620                 }
621                 
622                 public static void SetBar (object signatureMismatch)
623                 {
624                 }
625
626                 public static void GetBaz (object noReturnType)
627                 {
628                 }
629                 
630                 public static string SetBaz (object target, object extraReturnType)
631                 {
632                         return null;
633                 }
634
635                 protected static string GetProtected (object target)
636                 {
637                         string v;
638                         return AttachablePropertyServices.TryGetProperty (target, ProtectedIdentifier, out v) ? v : null;
639                 }
640                 
641                 protected static void SetProtected (object target, string value)
642                 {
643                         AttachablePropertyServices.SetProperty (target, ProtectedIdentifier, value);
644                 }
645
646                 static Dictionary<object,List<EventHandler>> handlers = new Dictionary<object,List<EventHandler>> ();
647
648                 public static void AddXHandler (object target, EventHandler handler)
649                 {
650                         List<EventHandler> l;
651                         if (!handlers.TryGetValue (target, out l)) {
652                                 l = new List<EventHandler> ();
653                                 handlers [target] = l;
654                         }
655                         l.Add (handler);
656                 }
657
658                 public static void RemoveXHandler (object target, EventHandler handler)
659                 {
660                         handlers [target].Remove (handler);
661                 }
662         }
663         
664         public class AttachedPropertyStore : IAttachedPropertyStore
665         {
666                 public AttachedPropertyStore ()
667                 {
668                 }
669                 
670                 Dictionary<AttachableMemberIdentifier,object> props = new Dictionary<AttachableMemberIdentifier,object> ();
671
672                 public int PropertyCount {
673                         get { return props.Count; }
674                 }
675                 
676                 public void CopyPropertiesTo (KeyValuePair<AttachableMemberIdentifier, object> [] array, int index)
677                 {
678                         ((ICollection<KeyValuePair<AttachableMemberIdentifier, object>>) props).CopyTo (array, index);
679                 }
680                 
681                 public bool RemoveProperty (AttachableMemberIdentifier attachableMemberIdentifier)
682                 {
683                         return props.Remove (attachableMemberIdentifier);
684                 }
685                 
686                 public void SetProperty (AttachableMemberIdentifier attachableMemberIdentifier, object value)
687                 {
688                         props [attachableMemberIdentifier] = value;
689                 }
690                 
691                 public bool TryGetProperty (AttachableMemberIdentifier attachableMemberIdentifier, out object value)
692                 {
693                         return props.TryGetValue (attachableMemberIdentifier, out value);
694                 }
695         }
696
697         public class AttachedWrapper : AttachedPropertyStore
698         {
699                 public AttachedWrapper ()
700                 {
701                         Value = new Attached ();
702                 }
703
704                 public Attached Value { get; set; }
705         }
706
707         public class AttachedWrapper2
708         {
709                 public static readonly AttachableMemberIdentifier FooIdentifier = new AttachableMemberIdentifier (typeof (AttachedWrapper2), "Foo");
710
711                 static AttachedPropertyStore store = new AttachedPropertyStore ();
712
713                 public static string GetFoo (object target)
714                 {
715                         object v;
716                         return store.TryGetProperty (FooIdentifier, out v) ? (string) v : null;
717                 }
718                 
719                 public static void SetFoo (object target, string value)
720                 {
721                         store.SetProperty (FooIdentifier, value);
722                 }
723
724                 public static int PropertyCount {
725                         get { return store.PropertyCount; }
726                 }
727
728                 public AttachedWrapper2 ()
729                 {
730                         Value = new Attached ();
731                 }
732
733                 public Attached Value { get; set; }
734         }
735
736         public class Attached : Attachable
737         {
738         }
739
740         public class Attached2
741         {
742                 internal String Property { get; set; }
743         }
744         
745         public class AttachedWrapper3
746         {
747                 public static void SetProperty (Attached2 a, string value)
748                 {
749                         a.Property = value;
750                 }
751         }
752
753         public class EventStore
754         {
755                 public bool Method1Invoked;
756
757                 public event EventHandler<EventArgs> Event1;
758                 public event Func<object> Event2;
759
760                 public object Examine ()
761                 {
762                         if (Event1 != null)
763                                 Event1 (this, EventArgs.Empty);
764                         if (Event2 != null)
765                                 return Event2 ();
766                         else
767                                 return null;
768                 }
769
770                 public void Method1 ()
771                 {
772                         throw new Exception ();
773                 }
774
775                 public void Method1 (object o, EventArgs e)
776                 {
777                         Method1Invoked = true;
778                 }
779
780                 public object Method2 ()
781                 {
782                         return "foo";
783                 }
784         }
785
786         public class EventStore2<TEventArgs> where TEventArgs : EventArgs
787         {
788                 public bool Method1Invoked;
789
790                 public event EventHandler<TEventArgs> Event1;
791                 public event Func<object> Event2;
792
793                 public object Examine ()
794                 {
795                         if (Event1 != null)
796                                 Event1 (this, default (TEventArgs));
797                         if (Event2 != null)
798                                 return Event2 ();
799                         else
800                                 return null;
801                 }
802
803                 public void Method1 ()
804                 {
805                         throw new Exception ();
806                 }
807
808                 public void Method1 (object o, EventArgs e)
809                 {
810                         throw new Exception ();
811                 }
812
813                 public void Method1 (object o, TEventArgs e)
814                 {
815                         Method1Invoked = true;
816                 }
817
818                 public object Method2 ()
819                 {
820                         return "foo";
821                 }
822         }
823
824         public class AbstractContainer
825         {
826                 public AbstractObject Value1 { get; set; }
827                 public AbstractObject Value2 { get; set; }
828         }
829         
830         public abstract class AbstractObject
831         {
832                 public abstract string Foo { get; set; }
833         }
834
835         public class DerivedObject : AbstractObject
836         {
837                 public override string Foo { get; set; }
838         }
839
840         public class ReadOnlyPropertyContainer
841         {
842                 string foo;
843                 public string Foo {
844                         get { return foo; }
845                         set { foo = Bar = value; }
846                 }
847                 public string Bar { get; private set; }
848         }
849
850         public class EnumContainer
851         {
852                 public EnumValueType EnumProperty { get; set; }
853         }
854
855         public enum EnumValueType
856         {
857                 One,
858                 Two,
859                 Three,
860                 Four
861         }
862
863         [ContentProperty ("ListOfItems")]
864         public class CollectionContentProperty
865         {
866                 public IList<SimpleClass> ListOfItems { get; set; }
867
868                 public CollectionContentProperty ()
869                 {
870                         this.ListOfItems = new List<SimpleClass> ();
871                 }
872         }
873
874         [ContentProperty ("ListOfItems")]
875         public class CollectionContentPropertyX
876         {
877                 public IList ListOfItems { get; set; }
878
879                 public CollectionContentPropertyX ()
880                 {
881                         this.ListOfItems = new List<IEnumerable> ();
882                 }
883         }
884
885         public class SimpleClass
886         {
887         }
888
889         public class NullableContainer
890         {
891                 public int? TestProp { get; set; }
892         }
893
894         public class DirectListContainer // for such xml that directly contains items in <*.Items> element.
895         {
896                 public IList<DirectListContent> Items { get; set; }
897
898                 public DirectListContainer ()
899                 {
900                         this.Items = new List<DirectListContent> ();
901                 }
902         }
903
904         public class DirectListContent
905         {
906                 public string Value { get; set; }
907         }
908
909         public class DirectDictionaryContainer // for such xml that directly contains items in <*.Items> element.
910         {
911                 public IDictionary<EnumValueType,int> Items { get; set; }
912
913                 public DirectDictionaryContainer ()
914                 {
915                         this.Items = new Dictionary<EnumValueType,int> ();
916                 }
917         }
918 }
919
920 namespace XamlTest
921 {
922         public class Configurations : List<Configuration>
923         {
924                 private Configuration active;
925                 private bool isFrozen;
926
927                 public Configuration Active {
928                         get { return this.active; }
929                         set {
930                                 if (this.isFrozen) {
931                                 throw new InvalidOperationException ("The 'Active' configuration can only be changed via modifying the source file (" + this.Source + ").");
932                                 }
933
934                                 this.active = value;
935                         }
936                 }
937
938                 public string Source { get; private set; }
939         }
940
941         public class Configuration
942         {
943                 public string Version { get; set; }
944
945                 public string Path { get; set; }
946         }
947 }
948
949 // see bug #681480
950 namespace SecondTest
951 {
952         public class TypeOtherAssembly
953         {
954                 [TypeConverter (typeof (NullableUintListConverter))]
955                 public List<uint?> Values { get; set; }
956
957                 public TypeOtherAssembly ()
958                 {
959                         this.Values = new List<uint?> ();
960                 }
961         }
962
963         public class NullableUintListConverter : CustomTypeConverterBase
964         {
965                 public override object ConvertFrom (System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
966                 {
967                         string configValue = value as string;
968                         if (string.IsNullOrWhiteSpace (configValue))
969                                 return null;
970
971                         string delimiterStr = ", ";
972                         char [] delimiters = delimiterStr.ToCharArray ();
973                         string [] tokens = configValue.Split (delimiters, StringSplitOptions.RemoveEmptyEntries);
974
975                         List<uint?> parsedList = new List<uint?> (tokens.Length);
976                         foreach (string token in tokens)
977                                 parsedList.Add(uint.Parse(token));
978
979                         return parsedList;
980                 }
981
982                 public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
983                 {
984                         var v = (List<uint?>) value;
985                         return String.Join (", ", (from i in v select i.ToString ()).ToArray ());
986                 }
987         }
988         
989         public class CustomTypeConverterBase : TypeConverter
990         {
991                 public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
992                 {
993                         if (sourceType == typeof (string))
994                         {
995                                 return true;
996                         }
997                         return base.CanConvertFrom (context, sourceType);
998                 }
999         }
1000
1001         #region bug #681202
1002
1003         [MarkupExtensionReturnType (typeof (object))]
1004         public class ResourceExtension : MarkupExtension
1005         {
1006                 [ConstructorArgument ("key")]
1007                 public object Key { get; set; }
1008
1009                 public ResourceExtension (object key)
1010                 {
1011                         this.Key = key;
1012                 }
1013
1014                 public override object ProvideValue (IServiceProvider serviceProvider)
1015                 {
1016                         IXamlSchemaContextProvider service = serviceProvider.GetService (typeof (IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;
1017                         IAmbientProvider provider = serviceProvider.GetService (typeof (IAmbientProvider)) as IAmbientProvider;
1018                         Debug.Assert (provider != null, "The provider should not be null!");
1019
1020                         XamlSchemaContext schemaContext = service.SchemaContext;
1021                         XamlType[] types = new XamlType [] { schemaContext.GetXamlType (typeof (ResourcesDict)) };
1022
1023                         // ResourceDict is marked as Ambient, so the instance current being deserialized should be in this list.
1024                         List<AmbientPropertyValue> list = provider.GetAllAmbientValues (null, false, types) as List<AmbientPropertyValue>;
1025                         if (list.Count != 1)
1026                                 throw new Exception ("expected ambient property count == 1 but " + list.Count);
1027                         for (int i = 0; i < list.Count; i++) {
1028                                 AmbientPropertyValue value = list [i];
1029                                 ResourcesDict dict = value.Value as ResourcesDict;
1030
1031                                 // For this example, we know that dict should not be null and that it is the only value in list.
1032                                 object result = dict [this.Key];
1033                                 return result;
1034                         }
1035
1036                         return null;
1037                 }
1038         }
1039
1040         [UsableDuringInitialization (true), Ambient]
1041         public class ResourcesDict : Dictionary<object, object>
1042         {
1043         }
1044
1045         public class TestObject
1046         {
1047                 public TestObject TestProperty { get; set; }
1048         }
1049
1050         #endregion
1051
1052         public class ResourcesDict2 : Dictionary<object, object>
1053         {
1054         }
1055
1056         public class TestObject2
1057         {
1058                 public string TestProperty { get; set; }
1059         }
1060
1061         #region bug #683290
1062         [ContentProperty ("Items")]
1063         public class SimpleType
1064         {
1065                 public IList<SimpleType> Items { get; set; }
1066                 
1067                 public IList<SimpleType> NonContentItems { get; set; }
1068                 
1069                 public string TestProperty { get; set; }
1070                 
1071                 public SimpleType ()
1072                 {
1073                         this.Items = new List<SimpleType> ();
1074                         this.NonContentItems=new List<SimpleType> ();
1075                 }
1076         }
1077         
1078         public class ContentPropertyContainer : Dictionary<object, object>
1079         {
1080         }
1081         #endregion
1082 }
1083
1084