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