2 // System.Xml.XmlSerializerTestClasses
5 // Erik LeBel <eriklebel@yahoo.ca>
6 // Hagit Yidov <hagity@mainsoft.com>
9 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
11 // Classes to use in the testing of the XmlSerializer
15 using System.Collections;
17 using System.Collections.Generic;
19 using System.ComponentModel;
21 using System.Xml.Schema;
22 using System.Xml.Serialization;
24 namespace MonoTests.System.Xml.TestClasses
26 public enum SimpleEnumeration { FIRST, SECOND };
29 public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
30 public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
44 [SoapType ("flagenum")]
45 public enum FlagEnum_Encoded
56 public enum ZeroFlagEnum
62 [XmlEnum ("tns:t<w>o")]
69 #region GenericsTestClasses
72 public class GenSimpleClass<T>
74 public T something = default (T);
77 public struct GenSimpleStruct<T>
80 public GenSimpleStruct (int dummy)
82 something = default (T);
86 public class GenListClass<T>
88 public List<T> somelist = new List<T> ();
91 public class GenArrayClass<T>
93 public T[] arr = new T[3];
96 public class GenTwoClass<T1, T2>
98 public T1 something1 = default (T1);
99 public T2 something2 = default (T2);
102 public class GenDerivedClass<T1, T2> : GenTwoClass<string, int>
104 public T1 another1 = default (T1);
105 public T2 another2 = default (T2);
108 public class GenDerived2Class<T1, T2> : GenTwoClass<T1, T2>
110 public T1 another1 = default (T1);
111 public T2 another2 = default (T2);
114 public class GenNestedClass<TO, TI>
116 public TO outer = default (TO);
117 public class InnerClass<T>
119 public TI inner = default (TI);
120 public T something = default (T);
124 public struct GenComplexStruct<T1, T2>
127 public GenSimpleClass<T1> simpleclass;
128 public GenSimpleStruct<T1> simplestruct;
129 public GenListClass<T1> listclass;
130 public GenArrayClass<T1> arrayclass;
131 public GenTwoClass<T1, T2> twoclass;
132 public GenDerivedClass<T1, T2> derivedclass;
133 public GenDerived2Class<T1, T2> derived2;
134 public GenNestedClass<T1, T2> nestedouter;
135 public GenNestedClass<T1, T2>.InnerClass<T1> nestedinner;
136 public GenComplexStruct (int dummy)
138 something = default (T1);
139 simpleclass = new GenSimpleClass<T1> ();
140 simplestruct = new GenSimpleStruct<T1> ();
141 listclass = new GenListClass<T1> ();
142 arrayclass = new GenArrayClass<T1> ();
143 twoclass = new GenTwoClass<T1, T2> ();
144 derivedclass = new GenDerivedClass<T1, T2> ();
145 derived2 = new GenDerived2Class<T1, T2> ();
146 nestedouter = new GenNestedClass<T1, T2> ();
147 nestedinner = new GenNestedClass<T1, T2>.InnerClass<T1> ();
151 public class WithNulls
153 [XmlElement (IsNullable=true)]
156 [XmlElement (IsNullable=true)]
157 public TestEnumWithNulls? nenum;
159 [XmlElement (IsNullable=true)]
160 public DateTime? ndate;
163 public enum TestEnumWithNulls
171 #endregion // GenericsTestClasses
173 public class SimpleClass
175 public string something = null;
178 public class StringCollection : CollectionBase
180 public void Add (String parameter)
182 List.Insert (Count, parameter);
185 public String this[int index]
189 if (index < 0 || index > Count)
190 throw new ArgumentOutOfRangeException ();
192 return (String) List[index];
194 set { List[index] = value; }
198 public class StringCollectionContainer
200 StringCollection messages = new StringCollection ();
202 public StringCollection Messages
204 get { return messages; }
208 public class ArrayContainer
210 public object[] items = null;
213 public class ClassArrayContainer
215 public SimpleClass[] items = null;
219 public class SimpleClassWithXmlAttributes
221 [XmlAttribute ("member")]
222 public string something = null;
228 [XmlAttribute ("flag1")]
230 public FlagEnum Flags1;
232 [XmlAttribute ("flag2")]
233 [DefaultValue (FlagEnum.e1)]
234 public FlagEnum Flags2;
236 [XmlAttribute ("flag3", Form = XmlSchemaForm.Qualified)]
237 [DefaultValue (FlagEnum.e1 | FlagEnum.e2)]
238 public FlagEnum Flags3;
240 [XmlAttribute ("flag4")]
241 public FlagEnum Flags4;
243 [XmlAttribute ("modifiers")]
244 public MapModifiers Modifiers;
246 [XmlAttribute ("modifiers2", Form = XmlSchemaForm.Unqualified)]
247 public MapModifiers Modifiers2;
249 [XmlAttribute ("modifiers3")]
251 public MapModifiers Modifiers3;
253 [XmlAttribute ("modifiers4", Form = XmlSchemaForm.Unqualified)]
254 [DefaultValue (MapModifiers.Protected)]
255 public MapModifiers Modifiers4;
257 [XmlAttribute ("modifiers5", Form = XmlSchemaForm.Qualified)]
258 [DefaultValue (MapModifiers.Public)]
259 public MapModifiers Modifiers5;
261 [XmlAttribute ("names")]
262 public string[] Names;
264 [XmlAttribute ("street")]
265 public string Street;
268 [SoapType ("field", Namespace = "some:urn")]
269 public class Field_Encoded
271 [SoapAttribute ("flag1")]
272 [DefaultValue (FlagEnum_Encoded.e1)]
273 public FlagEnum_Encoded Flags1;
275 [SoapAttribute ("flag2")]
276 [DefaultValue (FlagEnum_Encoded.e1)]
277 public FlagEnum_Encoded Flags2;
279 [SoapAttribute ("flag3")]
280 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e2)]
281 public FlagEnum_Encoded Flags3;
283 [SoapAttribute ("flag4")]
284 public FlagEnum_Encoded Flags4;
286 [SoapAttribute ("modifiers")]
287 public MapModifiers Modifiers;
289 [SoapAttribute ("modifiers2")]
290 public MapModifiers Modifiers2;
292 [SoapAttribute ("modifiers3")]
293 [DefaultValue (MapModifiers.Public)]
294 public MapModifiers Modifiers3;
296 [SoapAttribute ("modifiers4")]
297 [DefaultValue (MapModifiers.Protected)]
298 public MapModifiers Modifiers4;
300 [SoapAttribute ("modifiers5")]
301 [DefaultValue (MapModifiers.Public)]
302 public MapModifiers Modifiers5;
304 public string[] Names;
306 [SoapAttribute ("street")]
307 public string Street;
311 public enum MapModifiers
314 [SoapEnum ("PuBlIc")]
316 [XmlEnum ("protected")]
320 public class MyList : ArrayList
324 // NOTE: MyList has no public constructor
325 public MyList (object container)
328 this.container = container;
332 public class Container
338 Items = new MyList (this);
342 public class Container2
350 public Container2 (bool b)
352 Items = new MyList (this);
356 public class MyElem : XmlElement
358 public MyElem (XmlDocument doc)
359 : base ("", "myelem", "", doc)
361 SetAttribute ("aa", "1");
368 public class MyDocument : XmlDocument
378 public class CDataContainer
380 public XmlCDataSection cdata;
383 public class NodeContainer
390 [XmlElementAttribute ("ChoiceZero", typeof (string), IsNullable = false)]
391 [XmlElementAttribute ("ChoiceOne", typeof (string), IsNullable = false)]
392 [XmlElementAttribute ("ChoiceTwo", typeof (string), IsNullable = false)]
393 [XmlChoiceIdentifier ("ItemType")]
394 public string MyChoice;
397 public ItemChoiceType ItemType;
400 [XmlType (IncludeInSchema = false)]
401 public enum ItemChoiceType
404 [XmlEnum ("ChoiceOne")]
409 public class WrongChoices
411 [XmlElementAttribute ("ChoiceZero", typeof (string), IsNullable = false)]
412 [XmlElementAttribute ("StrangeOne", typeof (string), IsNullable = false)]
413 [XmlElementAttribute ("ChoiceTwo", typeof (string), IsNullable = false)]
414 [XmlChoiceIdentifier ("ItemType")]
415 public string MyChoice;
418 public ItemChoiceType ItemType;
421 [XmlType ("Type with space")]
422 public class TestSpace
424 [XmlElement (ElementName = "Element with space")]
427 [XmlAttribute (AttributeName = "Attribute with space")]
432 public class ReadOnlyProperties
434 string[] strArr = new string[2] { "string1", "string2" };
436 public string[] StrArr
438 get { return strArr; }
443 get { return "fff"; }
448 public class ListDefaults
450 public ListDefaults ()
452 ed = new SimpleClass ();
456 public ArrayList list2;
460 public string[] list4;
462 [XmlElement ("e", typeof (SimpleClass))]
463 public ArrayList list5;
465 [DefaultValue (null)]
466 public SimpleClass ed;
468 [DefaultValue (null)]
472 public class clsPerson
474 public IList EmailAccounts;
477 public class ArrayClass
479 public object names = new object[] { "un", "dos" };
482 public class CompositeValueType
486 Items = new object[] { 1, 2 };
487 ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
490 [XmlElementAttribute ("Es", typeof (int))]
491 [XmlElementAttribute ("In", typeof (int))]
492 [XmlChoiceIdentifierAttribute ("ItemsElementName")]
493 public object[] Items;
495 [XmlElementAttribute ("ItemsElementName")]
496 [XmlIgnoreAttribute ()]
497 public ItemsChoiceType[] ItemsElementName;
500 public enum ItemsChoiceType
505 public class ArrayAttributeWithType
507 [XmlAttribute (DataType = "anyURI")]
508 public string[] at = new string[] { "a", "b" };
510 [XmlAttribute (DataType = "base64Binary")]
511 public byte[][] bin1 = new byte[][] { new byte[] { 1, 2 }, new byte[] { 1, 2 } };
513 [XmlAttribute (DataType = "base64Binary")]
514 public byte[] bin2 = new byte[] { 1, 2 };
517 public class ArrayAttributeWithWrongType
519 [XmlAttribute (DataType = "int")]
520 public string[] at = new string[] { "a", "b" };
523 [XmlType ("Container")]
524 public class EntityContainer
526 EntityCollection collection1;
527 EntityCollection collection2;
528 EntityCollection collection3 = new EntityCollection ("root");
529 EntityCollection collection4 = new EntityCollection ("root");
531 [XmlArray (IsNullable = true)]
532 public EntityCollection Collection1
534 get { return collection1; }
535 set { collection1 = value; collection1.Container = "assigned"; }
538 [XmlArray (IsNullable = false)]
539 public EntityCollection Collection2
541 get { return collection2; }
542 set { collection2 = value; collection2.Container = "assigned"; }
545 [XmlArray (IsNullable = true)]
546 public EntityCollection Collection3
548 get { return collection3; }
549 set { collection3 = value; collection3.Container = "assigned"; }
552 [XmlArray (IsNullable = false)]
553 public EntityCollection Collection4
555 get { return collection4; }
556 set { collection4 = value; collection4.Container = "assigned"; }
560 [XmlType ("Container")]
561 public class ArrayEntityContainer
563 Entity[] collection1;
564 Entity[] collection2;
565 Entity[] collection3 = new Entity[0];
566 Entity[] collection4 = new Entity[0];
568 [XmlArray (IsNullable = true)]
569 public Entity[] Collection1
571 get { return collection1; }
572 set { collection1 = value; }
575 [XmlArray (IsNullable = false)]
576 public Entity[] Collection2
578 get { return collection2; }
579 set { collection2 = value; }
582 [XmlArray (IsNullable = true)]
583 public Entity[] Collection3
585 get { return collection3; }
586 set { collection3 = value; }
589 [XmlArray (IsNullable = false)]
590 public Entity[] Collection4
592 get { return collection4; }
593 set { collection4 = value; }
599 private string _name = string.Empty;
600 private string _parent = null;
605 get { return _name; }
606 set { _name = value; }
612 get { return _parent; }
613 set { _parent = value; }
617 public class EntityCollection : ArrayList
619 public string _container;
621 public EntityCollection ()
625 public EntityCollection (string c)
630 public string Container
632 get { return _container; }
633 set { _container = value; }
636 public int Add (Entity value)
638 if (_container != null)
639 value.Parent = _container;
641 return base.Add (value);
644 public new Entity this[int index]
646 get { return (Entity) base[index]; }
647 set { base[index] = value; }
651 [XmlType ("Container")]
652 public class ObjectWithReadonlyCollection
654 EntityCollection collection1 = new EntityCollection ("root");
656 public EntityCollection Collection1
658 get { return collection1; }
662 [XmlType ("Container")]
663 public class ObjectWithReadonlyNulCollection
665 EntityCollection collection1;
667 public EntityCollection Collection1
669 get { return collection1; }
673 [XmlType ("Container")]
674 public class ObjectWithReadonlyArray
676 Entity[] collection1 = new Entity[0];
678 public Entity[] Collection1
680 get { return collection1; }
684 [XmlInclude (typeof (SubclassTestSub))]
685 public class SubclassTestBase
689 public class SubclassTestSub : SubclassTestBase
693 public class SubclassTestExtra
697 public class SubclassTestContainer
699 [XmlElement ("a", typeof (SubclassTestBase))]
700 [XmlElement ("b", typeof (SubclassTestExtra))]
704 public class DictionaryWithIndexer : DictionaryBase
706 public TimeSpan this[int index]
708 get { return TimeSpan.MinValue; }
711 public void Add (TimeSpan value)
716 [XmlRoot (Namespace = "some:urn")]
717 [SoapTypeAttribute (Namespace = "another:urn")]
718 public class PrimitiveTypesContainer
720 public PrimitiveTypesContainer ()
725 Password = new byte[] { 243, 15 };
726 PathSeparatorCharacter = '/';
732 public byte[] Password;
733 public char PathSeparatorCharacter;
736 public class TestSchemaForm1
738 public PrintTypeResponse p1;
740 [XmlElement (Namespace = "urn:oo")]
741 public PrintTypeResponse p2;
744 [XmlType (Namespace = "urn:testForm")]
745 public class TestSchemaForm2
747 public PrintTypeResponse p1;
749 [XmlElement (Namespace = "urn:oo")]
750 public PrintTypeResponse p2;
753 [XmlType (Namespace = "urn:responseTypes")]
754 public class PrintTypeResponse
756 [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
757 public OutputType result;
758 public PrintTypeResponse intern;
762 result = new OutputType ();
763 result.data = "data1";
764 intern = new PrintTypeResponse ();
765 intern.result = new OutputType ();
766 intern.result.data = "data2";
770 [XmlType (Namespace = "urn:responseTypes")]
771 public class OutputType
774 [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
778 [XmlRootAttribute ("testDefault", Namespace = "urn:myNS", IsNullable = false)]
779 [SoapType ("testDefault", Namespace = "urn:myNS")]
780 public class TestDefault
784 [DefaultValue ("Default Value")]
785 public string strDefault = "Default Value";
787 [DefaultValue (true)]
788 public bool boolT = true;
790 [DefaultValue (false)]
791 public bool boolF = false;
793 [DefaultValue (typeof (decimal), "10")]
794 public decimal decimalval = 10m;
796 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
797 public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
799 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
800 public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
803 [XmlType ("optionalValueType", Namespace = "some:urn")]
804 [XmlRootAttribute ("optionalValue", Namespace = "another:urn", IsNullable = false)]
805 public class OptionalValueTypeContainer
807 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
808 public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
810 [DefaultValue (FlagEnum.e1)]
811 public FlagEnum Flags = FlagEnum.e1;
815 public bool FlagsSpecified;
817 [DefaultValue (false)]
822 public bool IsEmptySpecified
824 get { return _isEmptySpecified; }
825 set { _isEmptySpecified = value; }
828 [DefaultValue (false)]
831 private bool _isEmptySpecified;
836 [SoapAttribute (Namespace = "http://www.cpandl.com")]
837 public string GroupName;
839 [SoapAttribute (DataType = "base64Binary")]
840 public Byte[] GroupNumber;
842 [SoapAttribute (DataType = "date", AttributeName = "CreationDate")]
843 public DateTime Today;
845 [SoapElement (DataType = "nonNegativeInteger", ElementName = "PosInt")]
846 public string PostitiveInt;
849 public bool IgnoreThis;
851 [DefaultValue (GroupType.B)]
852 public GroupType Grouptype;
853 public Vehicle MyVehicle;
855 [SoapInclude (typeof (Car))]
856 public Vehicle myCar (string licNumber)
859 if (licNumber == string.Empty) {
861 v.licenseNumber = "!!!!!!";
865 v.licenseNumber = licNumber;
871 [SoapInclude (typeof (Car))]
872 public abstract class Vehicle
874 public string licenseNumber;
875 [SoapElement (DataType = "date")]
876 public DateTime makeDate;
877 [DefaultValue ("450")]
878 public string weight;
881 public class Car : Vehicle
885 public enum GroupType
893 public class ErrorneousGetSchema : IXmlSerializable
895 public XmlSchema GetSchema ()
897 throw new ApplicationException ("unexpected");
900 public void ReadXml (XmlReader reader)
904 public void WriteXml (XmlWriter writer)
908 // it should be serialized IF it is NOT IXmlSerializable.
909 public string Whoa = "whoa";