XmlSerializerTestClasses.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // System.Xml.XmlSerializerTestClasses
  3. //
  4. // Author:
  5. // Erik LeBel <[email protected]>
  6. //
  7. // (C) 2003 Erik LeBel
  8. //
  9. // Classes to use in the testing of the XmlSerializer
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.Xml.Serialization;
  14. using System.Xml;
  15. namespace MonoTests.System.Xml.TestClasses
  16. {
  17. public enum SimpleEnumeration { FIRST, SECOND };
  18. public class SimpleClass
  19. {
  20. public string something = null;
  21. }
  22. public class StringCollection : CollectionBase
  23. {
  24. public void Add (String parameter)
  25. {
  26. List.Insert (Count, parameter);
  27. }
  28. public String this [int index]
  29. {
  30. get
  31. {
  32. if (index < 0 || index > Count)
  33. throw new ArgumentOutOfRangeException ();
  34. return (String) List [index];
  35. }
  36. set { List [index] = value; }
  37. }
  38. }
  39. public class StringCollectionContainer
  40. {
  41. StringCollection messages = new StringCollection();
  42. public StringCollection Messages
  43. {
  44. get { return messages; }
  45. }
  46. }
  47. public class ArrayContainer
  48. {
  49. public object [] items = null;
  50. }
  51. public class ClassArrayContainer
  52. {
  53. public SimpleClass [] items = null;
  54. }
  55. [XmlRoot("simple")]
  56. public class SimpleClassWithXmlAttributes
  57. {
  58. [XmlAttribute("member")]
  59. public string something = null;
  60. }
  61. [XmlRoot("field")]
  62. public class Field
  63. {
  64. [XmlAttribute("modifiers")]
  65. public MapModifiers Modifiers;
  66. }
  67. [Flags]
  68. public enum MapModifiers
  69. {
  70. [XmlEnum("public")]
  71. Public = 0,
  72. [XmlEnum("protected")]
  73. Protected = 1,
  74. }
  75. public class MyList : ArrayList
  76. {
  77. object container;
  78. // NOTE: MyList has no public constructor
  79. public MyList (object container) : base()
  80. {
  81. this.container = container;
  82. }
  83. }
  84. public class Container
  85. {
  86. public MyList Items;
  87. public Container () {
  88. Items = new MyList(this);
  89. }
  90. }
  91. public class Container2
  92. {
  93. public MyList Items;
  94. public Container2 () {
  95. }
  96. public Container2 (bool b) {
  97. Items = new MyList(this);
  98. }
  99. }
  100. public class MyElem: XmlElement
  101. {
  102. public MyElem (XmlDocument doc): base ("","myelem","", doc)
  103. {
  104. SetAttribute ("aa","1");
  105. }
  106. [XmlAttribute]
  107. public int kk=1;
  108. }
  109. public class MyDocument: XmlDocument
  110. {
  111. public MyDocument ()
  112. {
  113. }
  114. [XmlAttribute]
  115. public int kk=1;
  116. }
  117. public class CDataContainer
  118. {
  119. public XmlCDataSection cdata;
  120. }
  121. public class NodeContainer
  122. {
  123. public XmlNode node;
  124. }
  125. public class Choices
  126. {
  127. [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
  128. [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
  129. [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
  130. [XmlChoiceIdentifier("ItemType")]
  131. public string MyChoice;
  132. [XmlIgnore]
  133. public ItemChoiceType ItemType;
  134. }
  135. [XmlType(IncludeInSchema = false)]
  136. public enum ItemChoiceType
  137. {
  138. ChoiceZero,
  139. [XmlEnum ("ChoiceOne")]
  140. StrangeOne,
  141. ChoiceTwo,
  142. }
  143. public class WrongChoices
  144. {
  145. [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
  146. [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
  147. [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
  148. [XmlChoiceIdentifier("ItemType")]
  149. public string MyChoice;
  150. [XmlIgnore]
  151. public ItemChoiceType ItemType;
  152. }
  153. [XmlType ("Type with space")]
  154. public class TestSpace
  155. {
  156. [XmlElement (ElementName = "Element with space")]
  157. public int elem;
  158. [XmlAttribute (AttributeName = "Attribute with space")]
  159. public int attr;
  160. }
  161. [Serializable]
  162. public class ReadOnlyProperties {
  163. string[] strArr = new string[2] { "string1", "string2" };
  164. public string[] StrArr {
  165. get { return strArr; }
  166. }
  167. public string dat {
  168. get { return "fff"; }
  169. }
  170. }
  171. }