XmlSerializerTestClasses.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. public class ArrayAttributeWithType
  220. {
  221. [XmlAttribute (DataType="anyURI")]
  222. public string[] at = new string [] { "a","b" };
  223. [XmlAttribute (DataType="base64Binary")]
  224. public byte[][] bin1 = new byte[][] { new byte[]{1,2}, new byte[]{1,2}};
  225. [XmlAttribute (DataType="base64Binary")]
  226. public byte[] bin2 = new byte[] { 1,2 };
  227. }
  228. public class ArrayAttributeWithWrongType
  229. {
  230. [XmlAttribute (DataType="int")]
  231. public string[] at = new string [] { "a","b" };
  232. }
  233. [XmlType ("Container")]
  234. public class EntityContainer
  235. {
  236. EntityCollection collection1;
  237. EntityCollection collection2;
  238. EntityCollection collection3 = new EntityCollection ("root");
  239. EntityCollection collection4 = new EntityCollection ("root");
  240. [XmlArray (IsNullable=true)]
  241. public EntityCollection Collection1 {
  242. get { return collection1; }
  243. set { collection1 = value; collection1.Container = "assigned"; }
  244. }
  245. [XmlArray (IsNullable=false)]
  246. public EntityCollection Collection2 {
  247. get { return collection2; }
  248. set { collection2 = value; collection2.Container = "assigned"; }
  249. }
  250. [XmlArray (IsNullable=true)]
  251. public EntityCollection Collection3 {
  252. get { return collection3; }
  253. set { collection3 = value; collection3.Container = "assigned"; }
  254. }
  255. [XmlArray (IsNullable=false)]
  256. public EntityCollection Collection4 {
  257. get { return collection4; }
  258. set { collection4 = value; collection4.Container = "assigned"; }
  259. }
  260. }
  261. [XmlType ("Container")]
  262. public class ArrayEntityContainer
  263. {
  264. Entity[] collection1;
  265. Entity[] collection2;
  266. Entity[] collection3 = new Entity [0];
  267. Entity[] collection4 = new Entity [0];
  268. [XmlArray (IsNullable=true)]
  269. public Entity[] Collection1 {
  270. get { return collection1; }
  271. set { collection1 = value; }
  272. }
  273. [XmlArray (IsNullable=false)]
  274. public Entity[] Collection2 {
  275. get { return collection2; }
  276. set { collection2 = value; }
  277. }
  278. [XmlArray (IsNullable=true)]
  279. public Entity[] Collection3 {
  280. get { return collection3; }
  281. set { collection3 = value; }
  282. }
  283. [XmlArray (IsNullable=false)]
  284. public Entity[] Collection4 {
  285. get { return collection4; }
  286. set { collection4 = value; }
  287. }
  288. }
  289. public class Entity
  290. {
  291. private string _name = string.Empty;
  292. private string _parent = null;
  293. [XmlAttribute]
  294. public string Name {
  295. get { return _name; }
  296. set { _name = value; }
  297. }
  298. [XmlIgnore]
  299. public string Parent {
  300. get { return _parent; }
  301. set { _parent = value; }
  302. }
  303. }
  304. public class EntityCollection : ArrayList
  305. {
  306. public string _container;
  307. public EntityCollection ()
  308. {
  309. }
  310. public EntityCollection (string c)
  311. {
  312. _container = c;
  313. }
  314. public string Container {
  315. get { return _container; }
  316. set { _container = value; }
  317. }
  318. public int Add (Entity value)
  319. {
  320. if(_container != null)
  321. value.Parent = _container;
  322. return base.Add(value);
  323. }
  324. public new Entity this[int index]
  325. {
  326. get { return (Entity) base[index]; }
  327. set { base[index] = value; }
  328. }
  329. }
  330. [XmlType ("Container")]
  331. public class ObjectWithReadonlyCollection
  332. {
  333. EntityCollection collection1 = new EntityCollection ("root");
  334. public EntityCollection Collection1 {
  335. get { return collection1; }
  336. }
  337. }
  338. [XmlType ("Container")]
  339. public class ObjectWithReadonlyNulCollection
  340. {
  341. EntityCollection collection1;
  342. public EntityCollection Collection1 {
  343. get { return collection1; }
  344. }
  345. }
  346. [XmlType ("Container")]
  347. public class ObjectWithReadonlyArray
  348. {
  349. Entity[] collection1 = new Entity [0];
  350. public Entity[] Collection1 {
  351. get { return collection1; }
  352. }
  353. }
  354. }