2 // System.Xml.XmlSerializerTestClasses
5 // Erik LeBel <eriklebel@yahoo.ca>
9 // Classes to use in the testing of the XmlSerializer
13 using System.ComponentModel;
14 using System.Collections;
16 using System.Xml.Schema;
17 using System.Xml.Serialization;
19 namespace MonoTests.System.Xml.TestClasses
21 public enum SimpleEnumeration { FIRST, SECOND };
24 public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
25 public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
28 public enum FlagEnum {
38 [SoapType ("flagenum")]
39 public enum FlagEnum_Encoded
50 public enum ZeroFlagEnum {
55 [XmlEnum ("tns:t<w>o")]
62 public class SimpleClass
64 public string something = null;
67 public class StringCollection : CollectionBase
69 public void Add (String parameter)
71 List.Insert (Count, parameter);
74 public String this [int index]
78 if (index < 0 || index > Count)
79 throw new ArgumentOutOfRangeException ();
81 return (String) List [index];
83 set { List [index] = value; }
87 public class StringCollectionContainer
89 StringCollection messages = new StringCollection();
91 public StringCollection Messages
93 get { return messages; }
97 public class ArrayContainer
99 public object [] items = null;
102 public class ClassArrayContainer
104 public SimpleClass [] items = null;
108 public class SimpleClassWithXmlAttributes
110 [XmlAttribute("member")]
111 public string something = null;
117 [XmlAttribute ("flag1")]
119 public FlagEnum Flags1;
121 [XmlAttribute ("flag2")]
122 [DefaultValue (FlagEnum.e1)]
123 public FlagEnum Flags2;
125 [XmlAttribute ("flag3", Form = XmlSchemaForm.Qualified)]
126 [DefaultValue (FlagEnum.e1 | FlagEnum.e2)]
127 public FlagEnum Flags3;
129 [XmlAttribute ("flag4")]
130 public FlagEnum Flags4;
132 [XmlAttribute("modifiers")]
133 public MapModifiers Modifiers;
135 [XmlAttribute ("modifiers2", Form=XmlSchemaForm.Unqualified)]
136 public MapModifiers Modifiers2;
138 [XmlAttribute ("modifiers3")]
140 public MapModifiers Modifiers3;
142 [XmlAttribute ("modifiers4", Form=XmlSchemaForm.Unqualified)]
143 [DefaultValue (MapModifiers.Protected)]
144 public MapModifiers Modifiers4;
146 [XmlAttribute ("modifiers5", Form = XmlSchemaForm.Qualified)]
147 [DefaultValue (MapModifiers.Public)]
148 public MapModifiers Modifiers5;
150 [XmlAttribute ("names")]
151 public string[] Names;
153 [XmlAttribute ("street")]
154 public string Street;
157 [SoapType ("field", Namespace = "some:urn")]
158 public class Field_Encoded
160 [SoapAttribute ("flag1")]
161 [DefaultValue (FlagEnum_Encoded.e1)]
162 public FlagEnum_Encoded Flags1;
164 [SoapAttribute ("flag2")]
165 [DefaultValue (FlagEnum_Encoded.e1)]
166 public FlagEnum_Encoded Flags2;
168 [SoapAttribute ("flag3")]
169 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e2)]
170 public FlagEnum_Encoded Flags3;
172 [SoapAttribute ("flag4")]
173 public FlagEnum_Encoded Flags4;
175 [SoapAttribute ("modifiers")]
176 public MapModifiers Modifiers;
178 [SoapAttribute ("modifiers2")]
179 public MapModifiers Modifiers2;
181 [SoapAttribute ("modifiers3")]
182 [DefaultValue (MapModifiers.Public)]
183 public MapModifiers Modifiers3;
185 [SoapAttribute ("modifiers4")]
186 [DefaultValue (MapModifiers.Protected)]
187 public MapModifiers Modifiers4;
189 [SoapAttribute ("modifiers5")]
190 [DefaultValue (MapModifiers.Public)]
191 public MapModifiers Modifiers5;
193 public string[] Names;
195 [SoapAttribute ("street")]
196 public string Street;
200 public enum MapModifiers
203 [SoapEnum ("PuBlIc")]
205 [XmlEnum("protected")]
209 public class MyList : ArrayList
213 // NOTE: MyList has no public constructor
214 public MyList (object container) : base()
216 this.container = container;
220 public class Container
224 public Container () {
225 Items = new MyList(this);
229 public class Container2
233 public Container2 () {
236 public Container2 (bool b) {
237 Items = new MyList(this);
241 public class MyElem: XmlElement
243 public MyElem (XmlDocument doc): base ("","myelem","", doc)
245 SetAttribute ("aa","1");
252 public class MyDocument: XmlDocument
262 public class CDataContainer
264 public XmlCDataSection cdata;
267 public class NodeContainer
274 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
275 [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
276 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
277 [XmlChoiceIdentifier("ItemType")]
278 public string MyChoice;
281 public ItemChoiceType ItemType;
284 [XmlType(IncludeInSchema = false)]
285 public enum ItemChoiceType
288 [XmlEnum ("ChoiceOne")]
293 public class WrongChoices
295 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
296 [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
297 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
298 [XmlChoiceIdentifier("ItemType")]
299 public string MyChoice;
302 public ItemChoiceType ItemType;
305 [XmlType ("Type with space")]
306 public class TestSpace
308 [XmlElement (ElementName = "Element with space")]
311 [XmlAttribute (AttributeName = "Attribute with space")]
316 public class ReadOnlyProperties {
317 string[] strArr = new string[2] { "string1", "string2" };
319 public string[] StrArr {
320 get { return strArr; }
324 get { return "fff"; }
329 public class ListDefaults
331 public ListDefaults ()
333 ed = new SimpleClass ();
337 public ArrayList list2;
341 public string[] list4;
343 [XmlElement("e", typeof(SimpleClass))]
344 public ArrayList list5;
346 [DefaultValue (null)]
347 public SimpleClass ed;
349 [DefaultValue (null)]
353 public class clsPerson
355 public IList EmailAccounts;
358 public class ArrayClass
360 public object names = new object[] { "un","dos" };
363 public class CompositeValueType
367 Items = new object[] { 1, 2 };
368 ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
371 [XmlElementAttribute("Es", typeof(int))]
372 [XmlElementAttribute("In", typeof(int))]
373 [XmlChoiceIdentifierAttribute("ItemsElementName")]
374 public object[] Items;
376 [XmlElementAttribute("ItemsElementName")]
377 [XmlIgnoreAttribute()]
378 public ItemsChoiceType[] ItemsElementName;
381 public enum ItemsChoiceType {
385 public class ArrayAttributeWithType
387 [XmlAttribute (DataType="anyURI")]
388 public string[] at = new string [] { "a","b" };
390 [XmlAttribute (DataType="base64Binary")]
391 public byte[][] bin1 = new byte[][] { new byte[]{1,2}, new byte[]{1,2}};
393 [XmlAttribute (DataType="base64Binary")]
394 public byte[] bin2 = new byte[] { 1,2 };
397 public class ArrayAttributeWithWrongType
399 [XmlAttribute (DataType="int")]
400 public string[] at = new string [] { "a","b" };
403 [XmlType ("Container")]
404 public class EntityContainer
406 EntityCollection collection1;
407 EntityCollection collection2;
408 EntityCollection collection3 = new EntityCollection ("root");
409 EntityCollection collection4 = new EntityCollection ("root");
411 [XmlArray (IsNullable=true)]
412 public EntityCollection Collection1 {
413 get { return collection1; }
414 set { collection1 = value; collection1.Container = "assigned"; }
417 [XmlArray (IsNullable=false)]
418 public EntityCollection Collection2 {
419 get { return collection2; }
420 set { collection2 = value; collection2.Container = "assigned"; }
423 [XmlArray (IsNullable=true)]
424 public EntityCollection Collection3 {
425 get { return collection3; }
426 set { collection3 = value; collection3.Container = "assigned"; }
429 [XmlArray (IsNullable=false)]
430 public EntityCollection Collection4 {
431 get { return collection4; }
432 set { collection4 = value; collection4.Container = "assigned"; }
436 [XmlType ("Container")]
437 public class ArrayEntityContainer
439 Entity[] collection1;
440 Entity[] collection2;
441 Entity[] collection3 = new Entity [0];
442 Entity[] collection4 = new Entity [0];
444 [XmlArray (IsNullable=true)]
445 public Entity[] Collection1 {
446 get { return collection1; }
447 set { collection1 = value; }
450 [XmlArray (IsNullable=false)]
451 public Entity[] Collection2 {
452 get { return collection2; }
453 set { collection2 = value; }
456 [XmlArray (IsNullable=true)]
457 public Entity[] Collection3 {
458 get { return collection3; }
459 set { collection3 = value; }
462 [XmlArray (IsNullable=false)]
463 public Entity[] Collection4 {
464 get { return collection4; }
465 set { collection4 = value; }
471 private string _name = string.Empty;
472 private string _parent = null;
476 get { return _name; }
477 set { _name = value; }
481 public string Parent {
482 get { return _parent; }
483 set { _parent = value; }
487 public class EntityCollection : ArrayList
489 public string _container;
491 public EntityCollection ()
495 public EntityCollection (string c)
500 public string Container {
501 get { return _container; }
502 set { _container = value; }
505 public int Add (Entity value)
507 if(_container != null)
508 value.Parent = _container;
510 return base.Add(value);
513 public new Entity this[int index]
515 get { return (Entity) base[index]; }
516 set { base[index] = value; }
520 [XmlType ("Container")]
521 public class ObjectWithReadonlyCollection
523 EntityCollection collection1 = new EntityCollection ("root");
525 public EntityCollection Collection1 {
526 get { return collection1; }
530 [XmlType ("Container")]
531 public class ObjectWithReadonlyNulCollection
533 EntityCollection collection1;
535 public EntityCollection Collection1 {
536 get { return collection1; }
540 [XmlType ("Container")]
541 public class ObjectWithReadonlyArray
543 Entity[] collection1 = new Entity [0];
545 public Entity[] Collection1 {
546 get { return collection1; }
550 [XmlInclude (typeof(SubclassTestSub))]
551 public class SubclassTestBase
555 public class SubclassTestSub: SubclassTestBase
559 public class SubclassTestExtra
563 public class SubclassTestContainer
565 [XmlElement ("a", typeof(SubclassTestBase))]
566 [XmlElement ("b", typeof(SubclassTestExtra))]
570 public class DictionaryWithIndexer : DictionaryBase
572 public TimeSpan this[int index] {
573 get { return TimeSpan.MinValue; }
576 public void Add (TimeSpan value)
581 [XmlRoot(Namespace="some:urn")]
582 [SoapTypeAttribute (Namespace="another:urn")]
583 public class PrimitiveTypesContainer
585 public PrimitiveTypesContainer ()
590 Password = new byte[] { 243, 15 };
591 PathSeparatorCharacter = '/';
597 public byte[] Password;
598 public char PathSeparatorCharacter;
601 public class TestSchemaForm1
603 public PrintTypeResponse p1;
605 [XmlElement(Namespace="urn:oo")]
606 public PrintTypeResponse p2;
609 [XmlType (Namespace="urn:testForm")]
610 public class TestSchemaForm2
612 public PrintTypeResponse p1;
614 [XmlElement(Namespace="urn:oo")]
615 public PrintTypeResponse p2;
618 [XmlType (Namespace="urn:responseTypes")]
619 public class PrintTypeResponse {
620 [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
621 public OutputType result;
622 public PrintTypeResponse intern;
626 result = new OutputType ();
627 result.data = "data1";
628 intern = new PrintTypeResponse ();
629 intern.result = new OutputType ();
630 intern.result.data = "data2";
634 [XmlType (Namespace="urn:responseTypes")]
635 public class OutputType {
637 [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
641 [XmlRootAttribute ("testDefault", Namespace="urn:myNS", IsNullable=false)]
642 [SoapType("testDefault", Namespace="urn:myNS")]
643 public class TestDefault
647 [DefaultValue ("Default Value")]
648 public string strDefault = "Default Value";
650 [DefaultValue (true)]
651 public bool boolT = true;
653 [DefaultValue (false)]
654 public bool boolF = false;
656 [DefaultValue (typeof (decimal), "10")]
657 public decimal decimalval = 10m;
659 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
660 public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
662 [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
663 public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
666 [XmlType ("optionalValueType", Namespace="some:urn")]
667 [XmlRootAttribute ("optionalValue", Namespace="another:urn", IsNullable=false)]
668 public class OptionalValueTypeContainer
670 [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
671 public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
673 [DefaultValue (FlagEnum.e1)]
674 public FlagEnum Flags = FlagEnum.e1;
678 public bool FlagsSpecified;
680 [DefaultValue (false)]
685 public bool IsEmptySpecified {
686 get { return _isEmptySpecified; }
687 set { _isEmptySpecified = value; }
690 [DefaultValue (false)]
693 private bool _isEmptySpecified;
698 [SoapAttribute (Namespace = "http://www.cpandl.com")]
699 public string GroupName;
701 [SoapAttribute (DataType = "base64Binary")]
702 public Byte [] GroupNumber;
704 [SoapAttribute (DataType = "date", AttributeName = "CreationDate")]
705 public DateTime Today;
707 [SoapElement (DataType = "nonNegativeInteger", ElementName = "PosInt")]
708 public string PostitiveInt;
711 public bool IgnoreThis;
713 [DefaultValue (GroupType.B)]
714 public GroupType Grouptype;
715 public Vehicle MyVehicle;
717 [SoapInclude (typeof (Car))]
718 public Vehicle myCar (string licNumber)
721 if (licNumber == string.Empty) {
723 v.licenseNumber = "!!!!!!";
726 v.licenseNumber = licNumber;
732 [SoapInclude (typeof (Car))]
733 public abstract class Vehicle
735 public string licenseNumber;
736 [SoapElement (DataType = "date")]
737 public DateTime makeDate;
738 [DefaultValue ("450")]
739 public string weight;
742 public class Car: Vehicle
746 public enum GroupType