XmlSerializerTestClasses.cs 4.8 KB

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