2 // System.Xml.XmlSerializerTestClasses
\r
5 // Erik LeBel <eriklebel@yahoo.ca>
\r
7 // (C) 2003 Erik LeBel
\r
9 // Classes to use in the testing of the XmlSerializer
\r
13 using System.ComponentModel;
\r
14 using System.Collections;
\r
16 using System.Xml.Schema;
\r
17 using System.Xml.Serialization;
\r
19 namespace MonoTests.System.Xml.TestClasses
\r
21 public enum SimpleEnumeration { FIRST, SECOND };
\r
24 public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
\r
25 public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
\r
28 public enum FlagEnum {
\r
38 [SoapType ("flagenum")]
\r
39 public enum FlagEnum_Encoded
\r
50 public enum ZeroFlagEnum {
\r
55 [XmlEnum ("tns:t<w>o")]
\r
62 public class SimpleClass
\r
64 public string something = null;
\r
67 public class StringCollection : CollectionBase
\r
69 public void Add (String parameter)
\r
71 List.Insert (Count, parameter);
\r
74 public String this [int index]
\r
78 if (index < 0 || index > Count)
\r
79 throw new ArgumentOutOfRangeException ();
\r
81 return (String) List [index];
\r
83 set { List [index] = value; }
\r
87 public class StringCollectionContainer
\r
89 StringCollection messages = new StringCollection();
\r
91 public StringCollection Messages
\r
93 get { return messages; }
\r
97 public class ArrayContainer
\r
99 public object [] items = null;
\r
102 public class ClassArrayContainer
\r
104 public SimpleClass [] items = null;
\r
107 [XmlRoot("simple")]
\r
108 public class SimpleClassWithXmlAttributes
\r
110 [XmlAttribute("member")]
\r
111 public string something = null;
\r
117 [XmlAttribute ("flag1")]
\r
119 public FlagEnum Flags1;
\r
121 [XmlAttribute ("flag2")]
\r
122 [DefaultValue (FlagEnum.e1)]
\r
123 public FlagEnum Flags2;
\r
125 [XmlAttribute ("flag3", Form = XmlSchemaForm.Qualified)]
\r
126 [DefaultValue (FlagEnum.e1 | FlagEnum.e2)]
\r
127 public FlagEnum Flags3;
\r
129 [XmlAttribute ("flag4")]
\r
130 public FlagEnum Flags4;
\r
132 [XmlAttribute("modifiers")]
\r
133 public MapModifiers Modifiers;
\r
135 [XmlAttribute ("modifiers2", Form=XmlSchemaForm.Unqualified)]
\r
136 public MapModifiers Modifiers2;
\r
138 [XmlAttribute ("modifiers3")]
\r
140 public MapModifiers Modifiers3;
\r
142 [XmlAttribute ("modifiers4", Form=XmlSchemaForm.Unqualified)]
\r
143 [DefaultValue (MapModifiers.Protected)]
\r
144 public MapModifiers Modifiers4;
\r
146 [XmlAttribute ("modifiers5", Form = XmlSchemaForm.Qualified)]
\r
147 [DefaultValue (MapModifiers.Public)]
\r
148 public MapModifiers Modifiers5;
\r
150 [XmlAttribute ("names")]
\r
151 public string[] Names;
\r
153 [XmlAttribute ("street")]
\r
154 public string Street;
\r
157 [SoapType ("field", Namespace = "some:urn")]
\r
158 public class Field_Encoded
\r
160 [SoapAttribute ("flag1")]
\r
161 [DefaultValue (FlagEnum_Encoded.e1)]
\r
162 public FlagEnum_Encoded Flags1;
\r
164 [SoapAttribute ("flag2")]
\r
165 [DefaultValue (FlagEnum_Encoded.e1)]
\r
166 public FlagEnum_Encoded Flags2;
\r
168 [SoapAttribute ("flag3")]
\r
169 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e2)]
\r
170 public FlagEnum_Encoded Flags3;
\r
172 [SoapAttribute ("flag4")]
\r
173 public FlagEnum_Encoded Flags4;
\r
175 [SoapAttribute ("modifiers")]
\r
176 public MapModifiers Modifiers;
\r
178 [SoapAttribute ("modifiers2")]
\r
179 public MapModifiers Modifiers2;
\r
181 [SoapAttribute ("modifiers3")]
\r
182 [DefaultValue (MapModifiers.Public)]
\r
183 public MapModifiers Modifiers3;
\r
185 [SoapAttribute ("modifiers4")]
\r
186 [DefaultValue (MapModifiers.Protected)]
\r
187 public MapModifiers Modifiers4;
\r
189 [SoapAttribute ("modifiers5")]
\r
190 [DefaultValue (MapModifiers.Public)]
\r
191 public MapModifiers Modifiers5;
\r
193 public string[] Names;
\r
195 [SoapAttribute ("street")]
\r
196 public string Street;
\r
200 public enum MapModifiers
\r
202 [XmlEnum("public")]
\r
204 [XmlEnum("protected")]
\r
208 public class MyList : ArrayList
\r
212 // NOTE: MyList has no public constructor
\r
213 public MyList (object container) : base()
\r
215 this.container = container;
\r
219 public class Container
\r
221 public MyList Items;
\r
223 public Container () {
\r
224 Items = new MyList(this);
\r
228 public class Container2
\r
230 public MyList Items;
\r
232 public Container2 () {
\r
235 public Container2 (bool b) {
\r
236 Items = new MyList(this);
\r
240 public class MyElem: XmlElement
\r
242 public MyElem (XmlDocument doc): base ("","myelem","", doc)
\r
244 SetAttribute ("aa","1");
\r
251 public class MyDocument: XmlDocument
\r
253 public MyDocument ()
\r
261 public class CDataContainer
\r
263 public XmlCDataSection cdata;
\r
266 public class NodeContainer
\r
268 public XmlNode node;
\r
271 public class Choices
\r
273 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
\r
274 [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
\r
275 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
\r
276 [XmlChoiceIdentifier("ItemType")]
\r
277 public string MyChoice;
\r
280 public ItemChoiceType ItemType;
\r
283 [XmlType(IncludeInSchema = false)]
\r
284 public enum ItemChoiceType
\r
287 [XmlEnum ("ChoiceOne")]
\r
292 public class WrongChoices
\r
294 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
\r
295 [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
\r
296 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
\r
297 [XmlChoiceIdentifier("ItemType")]
\r
298 public string MyChoice;
\r
301 public ItemChoiceType ItemType;
\r
304 [XmlType ("Type with space")]
\r
305 public class TestSpace
\r
307 [XmlElement (ElementName = "Element with space")]
\r
310 [XmlAttribute (AttributeName = "Attribute with space")]
\r
315 public class ReadOnlyProperties {
\r
316 string[] strArr = new string[2] { "string1", "string2" };
\r
318 public string[] StrArr {
\r
319 get { return strArr; }
\r
322 public string dat {
\r
323 get { return "fff"; }
\r
328 public class ListDefaults
\r
330 public ListDefaults ()
\r
332 ed = new SimpleClass ();
\r
336 public ArrayList list2;
\r
338 public MyList list3;
\r
340 public string[] list4;
\r
342 [XmlElement("e", typeof(SimpleClass))]
\r
343 public ArrayList list5;
\r
345 [DefaultValue (null)]
\r
346 public SimpleClass ed;
\r
348 [DefaultValue (null)]
\r
349 public string str;
\r
352 public class clsPerson
\r
354 public IList EmailAccounts;
\r
357 public class ArrayClass
\r
359 public object names = new object[] { "un","dos" };
\r
362 public class CompositeValueType
\r
364 public void Init ()
\r
366 Items = new object[] { 1, 2 };
\r
367 ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
\r
370 [XmlElementAttribute("Es", typeof(int))]
\r
371 [XmlElementAttribute("In", typeof(int))]
\r
372 [XmlChoiceIdentifierAttribute("ItemsElementName")]
\r
373 public object[] Items;
\r
375 [XmlElementAttribute("ItemsElementName")]
\r
376 [XmlIgnoreAttribute()]
\r
377 public ItemsChoiceType[] ItemsElementName;
\r
380 public enum ItemsChoiceType {
\r
384 public class ArrayAttributeWithType
\r
386 [XmlAttribute (DataType="anyURI")]
\r
387 public string[] at = new string [] { "a","b" };
\r
389 [XmlAttribute (DataType="base64Binary")]
\r
390 public byte[][] bin1 = new byte[][] { new byte[]{1,2}, new byte[]{1,2}};
\r
392 [XmlAttribute (DataType="base64Binary")]
\r
393 public byte[] bin2 = new byte[] { 1,2 };
\r
396 public class ArrayAttributeWithWrongType
\r
398 [XmlAttribute (DataType="int")]
\r
399 public string[] at = new string [] { "a","b" };
\r
402 [XmlType ("Container")]
\r
403 public class EntityContainer
\r
405 EntityCollection collection1;
\r
406 EntityCollection collection2;
\r
407 EntityCollection collection3 = new EntityCollection ("root");
\r
408 EntityCollection collection4 = new EntityCollection ("root");
\r
410 [XmlArray (IsNullable=true)]
\r
411 public EntityCollection Collection1 {
\r
412 get { return collection1; }
\r
413 set { collection1 = value; collection1.Container = "assigned"; }
\r
416 [XmlArray (IsNullable=false)]
\r
417 public EntityCollection Collection2 {
\r
418 get { return collection2; }
\r
419 set { collection2 = value; collection2.Container = "assigned"; }
\r
422 [XmlArray (IsNullable=true)]
\r
423 public EntityCollection Collection3 {
\r
424 get { return collection3; }
\r
425 set { collection3 = value; collection3.Container = "assigned"; }
\r
428 [XmlArray (IsNullable=false)]
\r
429 public EntityCollection Collection4 {
\r
430 get { return collection4; }
\r
431 set { collection4 = value; collection4.Container = "assigned"; }
\r
435 [XmlType ("Container")]
\r
436 public class ArrayEntityContainer
\r
438 Entity[] collection1;
\r
439 Entity[] collection2;
\r
440 Entity[] collection3 = new Entity [0];
\r
441 Entity[] collection4 = new Entity [0];
\r
443 [XmlArray (IsNullable=true)]
\r
444 public Entity[] Collection1 {
\r
445 get { return collection1; }
\r
446 set { collection1 = value; }
\r
449 [XmlArray (IsNullable=false)]
\r
450 public Entity[] Collection2 {
\r
451 get { return collection2; }
\r
452 set { collection2 = value; }
\r
455 [XmlArray (IsNullable=true)]
\r
456 public Entity[] Collection3 {
\r
457 get { return collection3; }
\r
458 set { collection3 = value; }
\r
461 [XmlArray (IsNullable=false)]
\r
462 public Entity[] Collection4 {
\r
463 get { return collection4; }
\r
464 set { collection4 = value; }
\r
468 public class Entity
\r
470 private string _name = string.Empty;
\r
471 private string _parent = null;
\r
474 public string Name {
\r
475 get { return _name; }
\r
476 set { _name = value; }
\r
480 public string Parent {
\r
481 get { return _parent; }
\r
482 set { _parent = value; }
\r
486 public class EntityCollection : ArrayList
\r
488 public string _container;
\r
490 public EntityCollection ()
\r
494 public EntityCollection (string c)
\r
499 public string Container {
\r
500 get { return _container; }
\r
501 set { _container = value; }
\r
504 public int Add (Entity value)
\r
506 if(_container != null)
\r
507 value.Parent = _container;
\r
509 return base.Add(value);
\r
512 public new Entity this[int index]
\r
514 get { return (Entity) base[index]; }
\r
515 set { base[index] = value; }
\r
519 [XmlType ("Container")]
\r
520 public class ObjectWithReadonlyCollection
\r
522 EntityCollection collection1 = new EntityCollection ("root");
\r
524 public EntityCollection Collection1 {
\r
525 get { return collection1; }
\r
529 [XmlType ("Container")]
\r
530 public class ObjectWithReadonlyNulCollection
\r
532 EntityCollection collection1;
\r
534 public EntityCollection Collection1 {
\r
535 get { return collection1; }
\r
539 [XmlType ("Container")]
\r
540 public class ObjectWithReadonlyArray
\r
542 Entity[] collection1 = new Entity [0];
\r
544 public Entity[] Collection1 {
\r
545 get { return collection1; }
\r
549 [XmlInclude (typeof(SubclassTestSub))]
\r
550 public class SubclassTestBase
\r
554 public class SubclassTestSub: SubclassTestBase
\r
558 public class SubclassTestExtra
\r
562 public class SubclassTestContainer
\r
564 [XmlElement ("a", typeof(SubclassTestBase))]
\r
565 [XmlElement ("b", typeof(SubclassTestExtra))]
\r
566 public object data;
\r
569 public class DictionaryWithIndexer : DictionaryBase
\r
571 public TimeSpan this[int index] {
\r
572 get { return TimeSpan.MinValue; }
\r
575 public void Add (TimeSpan value)
\r
580 [XmlRoot(Namespace="some:urn")]
\r
581 [SoapTypeAttribute (Namespace="another:urn")]
\r
582 public class PrimitiveTypesContainer
\r
584 public PrimitiveTypesContainer ()
\r
587 Name = "some name";
\r
589 Password = new byte[] { 243, 15 };
\r
590 PathSeparatorCharacter = '/';
\r
594 public string Name;
\r
596 public byte[] Password;
\r
597 public char PathSeparatorCharacter;
\r
600 public class TestSchemaForm1
\r
602 public PrintTypeResponse p1;
\r
604 [XmlElement(Namespace="urn:oo")]
\r
605 public PrintTypeResponse p2;
\r
608 [XmlType (Namespace="urn:testForm")]
\r
609 public class TestSchemaForm2
\r
611 public PrintTypeResponse p1;
\r
613 [XmlElement(Namespace="urn:oo")]
\r
614 public PrintTypeResponse p2;
\r
617 [XmlType (Namespace="urn:responseTypes")]
\r
618 public class PrintTypeResponse {
\r
619 [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
\r
620 public OutputType result;
\r
621 public PrintTypeResponse intern;
\r
623 public void Init ()
\r
625 result = new OutputType ();
\r
626 result.data = "data1";
\r
627 intern = new PrintTypeResponse ();
\r
628 intern.result = new OutputType ();
\r
629 intern.result.data = "data2";
\r
633 [XmlType (Namespace="urn:responseTypes")]
\r
634 public class OutputType {
\r
636 [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
\r
637 public string data;
\r
640 [XmlRootAttribute ("testDefault", Namespace="urn:myNS", IsNullable=false)]
\r
641 [SoapType("testDefault", Namespace="urn:myNS")]
\r
642 public class TestDefault
\r
646 [DefaultValue ("Default Value")]
\r
647 public string strDefault = "Default Value";
\r
649 [DefaultValue (true)]
\r
650 public bool boolT = true;
\r
652 [DefaultValue (false)]
\r
653 public bool boolF = false;
\r
655 [DefaultValue (typeof (decimal), "10")]
\r
656 public decimal decimalval = 10m;
\r
658 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
\r
659 public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
\r
661 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
\r
662 public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
\r
665 [XmlType ("optionalValueType", Namespace="some:urn")]
\r
666 [XmlRootAttribute ("optionalValue", Namespace="another:urn", IsNullable=false)]
\r
667 public class OptionalValueTypeContainer
\r
669 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
\r
670 public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
\r
672 [DefaultValue (FlagEnum.e1)]
\r
673 public FlagEnum Flags = FlagEnum.e1;
\r
677 public bool FlagsSpecified;
\r
679 [DefaultValue (false)]
\r
680 public bool IsEmpty;
\r
684 public bool IsEmptySpecified {
\r
685 get { return _isEmptySpecified; }
\r
686 set { _isEmptySpecified = value; }
\r
689 [DefaultValue (false)]
\r
690 public bool IsNull;
\r
692 private bool _isEmptySpecified;
\r