XmlSerializerTestClasses.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.ComponentModel;
  13. using System.Collections;
  14. using System.Xml.Serialization;
  15. using System.Xml;
  16. namespace MonoTests.System.Xml.TestClasses
  17. {
  18. public enum SimpleEnumeration { FIRST, SECOND };
  19. [Flags]
  20. public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
  21. public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
  22. public class SimpleClass
  23. {
  24. public string something = null;
  25. }
  26. public class StringCollection : CollectionBase
  27. {
  28. public void Add (String parameter)
  29. {
  30. List.Insert (Count, parameter);
  31. }
  32. public String this [int index]
  33. {
  34. get
  35. {
  36. if (index < 0 || index > Count)
  37. throw new ArgumentOutOfRangeException ();
  38. return (String) List [index];
  39. }
  40. set { List [index] = value; }
  41. }
  42. }
  43. public class StringCollectionContainer
  44. {
  45. StringCollection messages = new StringCollection();
  46. public StringCollection Messages
  47. {
  48. get { return messages; }
  49. }
  50. }
  51. public class ArrayContainer
  52. {
  53. public object [] items = null;
  54. }
  55. public class ClassArrayContainer
  56. {
  57. public SimpleClass [] items = null;
  58. }
  59. [XmlRoot("simple")]
  60. public class SimpleClassWithXmlAttributes
  61. {
  62. [XmlAttribute("member")]
  63. public string something = null;
  64. }
  65. [XmlRoot("field")]
  66. public class Field
  67. {
  68. [XmlAttribute("modifiers")]
  69. public MapModifiers Modifiers;
  70. }
  71. [Flags]
  72. public enum MapModifiers
  73. {
  74. [XmlEnum("public")]
  75. Public = 0,
  76. [XmlEnum("protected")]
  77. Protected = 1,
  78. }
  79. public class MyList : ArrayList
  80. {
  81. object container;
  82. // NOTE: MyList has no public constructor
  83. public MyList (object container) : base()
  84. {
  85. this.container = container;
  86. }
  87. }
  88. public class Container
  89. {
  90. public MyList Items;
  91. public Container () {
  92. Items = new MyList(this);
  93. }
  94. }
  95. public class Container2
  96. {
  97. public MyList Items;
  98. public Container2 () {
  99. }
  100. public Container2 (bool b) {
  101. Items = new MyList(this);
  102. }
  103. }
  104. public class MyElem: XmlElement
  105. {
  106. public MyElem (XmlDocument doc): base ("","myelem","", doc)
  107. {
  108. SetAttribute ("aa","1");
  109. }
  110. [XmlAttribute]
  111. public int kk=1;
  112. }
  113. public class MyDocument: XmlDocument
  114. {
  115. public MyDocument ()
  116. {
  117. }
  118. [XmlAttribute]
  119. public int kk=1;
  120. }
  121. public class CDataContainer
  122. {
  123. public XmlCDataSection cdata;
  124. }
  125. public class NodeContainer
  126. {
  127. public XmlNode node;
  128. }
  129. public class Choices
  130. {
  131. [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
  132. [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
  133. [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
  134. [XmlChoiceIdentifier("ItemType")]
  135. public string MyChoice;
  136. [XmlIgnore]
  137. public ItemChoiceType ItemType;
  138. }
  139. [XmlType(IncludeInSchema = false)]
  140. public enum ItemChoiceType
  141. {
  142. ChoiceZero,
  143. [XmlEnum ("ChoiceOne")]
  144. StrangeOne,
  145. ChoiceTwo,
  146. }
  147. public class WrongChoices
  148. {
  149. [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
  150. [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
  151. [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
  152. [XmlChoiceIdentifier("ItemType")]
  153. public string MyChoice;
  154. [XmlIgnore]
  155. public ItemChoiceType ItemType;
  156. }
  157. [XmlType ("Type with space")]
  158. public class TestSpace
  159. {
  160. [XmlElement (ElementName = "Element with space")]
  161. public int elem;
  162. [XmlAttribute (AttributeName = "Attribute with space")]
  163. public int attr;
  164. }
  165. [Serializable]
  166. public class ReadOnlyProperties {
  167. string[] strArr = new string[2] { "string1", "string2" };
  168. public string[] StrArr {
  169. get { return strArr; }
  170. }
  171. public string dat {
  172. get { return "fff"; }
  173. }
  174. }
  175. [XmlRoot("root")]
  176. public class ListDefaults
  177. {
  178. public ListDefaults ()
  179. {
  180. ed = new SimpleClass ();
  181. str = "hola";
  182. }
  183. public ArrayList list2;
  184. public MyList list3;
  185. public string[] list4;
  186. [XmlElement("e", typeof(SimpleClass))]
  187. public ArrayList list5;
  188. [DefaultValue (null)]
  189. public SimpleClass ed;
  190. [DefaultValue (null)]
  191. public string str;
  192. }
  193. public class clsPerson
  194. {
  195. public IList EmailAccounts;
  196. }
  197. public class ArrayClass
  198. {
  199. public object names = new object[] { "un","dos" };
  200. }
  201. public class CompositeValueType
  202. {
  203. public void Init ()
  204. {
  205. Items = new object[] { 1, 2 };
  206. ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
  207. }
  208. [XmlElementAttribute("Es", typeof(int))]
  209. [XmlElementAttribute("In", typeof(int))]
  210. [XmlChoiceIdentifierAttribute("ItemsElementName")]
  211. public object[] Items;
  212. [XmlElementAttribute("ItemsElementName")]
  213. [XmlIgnoreAttribute()]
  214. public ItemsChoiceType[] ItemsElementName;
  215. }
  216. public enum ItemsChoiceType {
  217. In, Es
  218. }
  219. }