2 // System.Xml.XmlSerializerTestClasses
\r
5 // Erik LeBel <eriklebel@yahoo.ca>
\r
7 // (C) 2003 Erik LeBel
\r
9 // Classes to use in the testing of the XmlSerializer
\r
13 using System.ComponentModel;
\r
14 using System.Collections;
\r
15 using System.Xml.Serialization;
\r
18 namespace MonoTests.System.Xml.TestClasses
\r
20 public enum SimpleEnumeration { FIRST, SECOND };
\r
23 public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
\r
24 public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
\r
26 public class SimpleClass
\r
28 public string something = null;
\r
31 public class StringCollection : CollectionBase
\r
33 public void Add (String parameter)
\r
35 List.Insert (Count, parameter);
\r
38 public String this [int index]
\r
42 if (index < 0 || index > Count)
\r
43 throw new ArgumentOutOfRangeException ();
\r
45 return (String) List [index];
\r
47 set { List [index] = value; }
\r
51 public class StringCollectionContainer
\r
53 StringCollection messages = new StringCollection();
\r
55 public StringCollection Messages
\r
57 get { return messages; }
\r
61 public class ArrayContainer
\r
63 public object [] items = null;
\r
66 public class ClassArrayContainer
\r
68 public SimpleClass [] items = null;
\r
72 public class SimpleClassWithXmlAttributes
\r
74 [XmlAttribute("member")]
\r
75 public string something = null;
\r
81 [XmlAttribute("modifiers")]
\r
82 public MapModifiers Modifiers;
\r
86 public enum MapModifiers
\r
90 [XmlEnum("protected")]
\r
94 public class MyList : ArrayList
\r
98 // NOTE: MyList has no public constructor
\r
99 public MyList (object container) : base()
\r
101 this.container = container;
\r
105 public class Container
\r
107 public MyList Items;
\r
109 public Container () {
\r
110 Items = new MyList(this);
\r
114 public class Container2
\r
116 public MyList Items;
\r
118 public Container2 () {
\r
121 public Container2 (bool b) {
\r
122 Items = new MyList(this);
\r
126 public class MyElem: XmlElement
128 public MyElem (XmlDocument doc): base ("","myelem","", doc)
130 SetAttribute ("aa","1");
137 public class MyDocument: XmlDocument
147 public class CDataContainer
149 public XmlCDataSection cdata;
152 public class NodeContainer
157 public class Choices
\r
159 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
\r
160 [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
\r
161 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
\r
162 [XmlChoiceIdentifier("ItemType")]
\r
163 public string MyChoice;
\r
166 public ItemChoiceType ItemType;
\r
169 [XmlType(IncludeInSchema = false)]
\r
170 public enum ItemChoiceType
\r
173 [XmlEnum ("ChoiceOne")]
\r
178 public class WrongChoices
\r
180 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
\r
181 [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
\r
182 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
\r
183 [XmlChoiceIdentifier("ItemType")]
\r
184 public string MyChoice;
\r
187 public ItemChoiceType ItemType;
\r
190 [XmlType ("Type with space")]
191 public class TestSpace
193 [XmlElement (ElementName = "Element with space")]
196 [XmlAttribute (AttributeName = "Attribute with space")]
201 public class ReadOnlyProperties {
202 string[] strArr = new string[2] { "string1", "string2" };
204 public string[] StrArr {
205 get { return strArr; }
209 get { return "fff"; }
214 public class ListDefaults
216 public ListDefaults ()
218 ed = new SimpleClass ();
222 public ArrayList list2;
226 public string[] list4;
228 [XmlElement("e", typeof(SimpleClass))]
229 public ArrayList list5;
231 [DefaultValue (null)]
232 public SimpleClass ed;
234 [DefaultValue (null)]
238 public class clsPerson
240 public IList EmailAccounts;
243 public class ArrayClass
245 public object names = new object[] { "un","dos" };
248 public class CompositeValueType
252 Items = new object[] { 1, 2 };
253 ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
256 [XmlElementAttribute("Es", typeof(int))]
\r
257 [XmlElementAttribute("In", typeof(int))]
\r
258 [XmlChoiceIdentifierAttribute("ItemsElementName")]
\r
259 public object[] Items;
\r
261 [XmlElementAttribute("ItemsElementName")]
\r
262 [XmlIgnoreAttribute()]
\r
263 public ItemsChoiceType[] ItemsElementName;
\r
266 public enum ItemsChoiceType {
\r
270 public class ArrayAttributeWithType
272 [XmlAttribute (DataType="anyURI")]
273 public string[] at = new string [] { "a","b" };
275 [XmlAttribute (DataType="base64Binary")]
276 public byte[][] bin1 = new byte[][] { new byte[]{1,2}, new byte[]{1,2}};
278 [XmlAttribute (DataType="base64Binary")]
279 public byte[] bin2 = new byte[] { 1,2 };
282 public class ArrayAttributeWithWrongType
284 [XmlAttribute (DataType="int")]
285 public string[] at = new string [] { "a","b" };
288 [XmlType ("Container")]
289 public class EntityContainer
291 EntityCollection collection1;
292 EntityCollection collection2;
293 EntityCollection collection3 = new EntityCollection ("root");
294 EntityCollection collection4 = new EntityCollection ("root");
296 [XmlArray (IsNullable=true)]
297 public EntityCollection Collection1 {
298 get { return collection1; }
299 set { collection1 = value; collection1.Container = "assigned"; }
302 [XmlArray (IsNullable=false)]
303 public EntityCollection Collection2 {
304 get { return collection2; }
305 set { collection2 = value; collection2.Container = "assigned"; }
308 [XmlArray (IsNullable=true)]
309 public EntityCollection Collection3 {
310 get { return collection3; }
311 set { collection3 = value; collection3.Container = "assigned"; }
314 [XmlArray (IsNullable=false)]
315 public EntityCollection Collection4 {
316 get { return collection4; }
317 set { collection4 = value; collection4.Container = "assigned"; }
321 [XmlType ("Container")]
322 public class ArrayEntityContainer
324 Entity[] collection1;
325 Entity[] collection2;
326 Entity[] collection3 = new Entity [0];
327 Entity[] collection4 = new Entity [0];
329 [XmlArray (IsNullable=true)]
330 public Entity[] Collection1 {
331 get { return collection1; }
332 set { collection1 = value; }
335 [XmlArray (IsNullable=false)]
336 public Entity[] Collection2 {
337 get { return collection2; }
338 set { collection2 = value; }
341 [XmlArray (IsNullable=true)]
342 public Entity[] Collection3 {
343 get { return collection3; }
344 set { collection3 = value; }
347 [XmlArray (IsNullable=false)]
348 public Entity[] Collection4 {
349 get { return collection4; }
350 set { collection4 = value; }
356 private string _name = string.Empty;
357 private string _parent = null;
361 get { return _name; }
362 set { _name = value; }
366 public string Parent {
367 get { return _parent; }
368 set { _parent = value; }
372 public class EntityCollection : ArrayList
374 public string _container;
376 public EntityCollection ()
380 public EntityCollection (string c)
385 public string Container {
386 get { return _container; }
387 set { _container = value; }
390 public int Add (Entity value)
392 if(_container != null)
393 value.Parent = _container;
395 return base.Add(value);
398 public new Entity this[int index]
400 get { return (Entity) base[index]; }
401 set { base[index] = value; }
405 [XmlType ("Container")]
406 public class ObjectWithReadonlyCollection
408 EntityCollection collection1 = new EntityCollection ("root");
410 public EntityCollection Collection1 {
411 get { return collection1; }
415 [XmlType ("Container")]
416 public class ObjectWithReadonlyNulCollection
418 EntityCollection collection1;
420 public EntityCollection Collection1 {
421 get { return collection1; }
425 [XmlType ("Container")]
426 public class ObjectWithReadonlyArray
428 Entity[] collection1 = new Entity [0];
430 public Entity[] Collection1 {
431 get { return collection1; }