| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- //
- // System.Xml.XmlSerializerTestClasses
- //
- // Author:
- // Erik LeBel <[email protected]>
- //
- // (C) 2003 Erik LeBel
- //
- // Classes to use in the testing of the XmlSerializer
- //
- using System;
- using System.ComponentModel;
- using System.Collections;
- using System.Xml;
- using System.Xml.Schema;
- using System.Xml.Serialization;
- namespace MonoTests.System.Xml.TestClasses
- {
- public enum SimpleEnumeration { FIRST, SECOND };
- [Flags]
- public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
- public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
- [Flags]
- public enum FlagEnum {
- [XmlEnum ("one")]
- e1 = 1,
- [XmlEnum ("two")]
- e2 = 2,
- [XmlEnum ("four")]
- e4 = 4
- }
- [Flags]
- [SoapType ("flagenum")]
- public enum FlagEnum_Encoded
- {
- [SoapEnum ("one")]
- e1 = 1,
- [SoapEnum ("two")]
- e2 = 2,
- [SoapEnum ("four")]
- e4 = 4
- }
- [Flags]
- public enum ZeroFlagEnum {
- [XmlEnum ("zero")]
- e0 = 0,
- [XmlEnum ("o<n>e")]
- e1 = 1,
- [XmlEnum ("tns:t<w>o")]
- e2 = 2,
- [XmlEnum ("four")]
- [XmlIgnore]
- e4 = 4
- }
-
- public class SimpleClass
- {
- public string something = null;
- }
- public class StringCollection : CollectionBase
- {
- public void Add (String parameter)
- {
- List.Insert (Count, parameter);
- }
-
- public String this [int index]
- {
- get
- {
- if (index < 0 || index > Count)
- throw new ArgumentOutOfRangeException ();
-
- return (String) List [index];
- }
- set { List [index] = value; }
- }
- }
-
- public class StringCollectionContainer
- {
- StringCollection messages = new StringCollection();
-
- public StringCollection Messages
- {
- get { return messages; }
- }
- }
- public class ArrayContainer
- {
- public object [] items = null;
- }
-
- public class ClassArrayContainer
- {
- public SimpleClass [] items = null;
- }
-
- [XmlRoot("simple")]
- public class SimpleClassWithXmlAttributes
- {
- [XmlAttribute("member")]
- public string something = null;
- }
-
- [XmlRoot("field")]
- public class Field
- {
- [XmlAttribute ("flag1")]
- [DefaultValue (1)]
- public FlagEnum Flags1;
- [XmlAttribute ("flag2")]
- [DefaultValue (FlagEnum.e1)]
- public FlagEnum Flags2;
- [XmlAttribute ("flag3", Form = XmlSchemaForm.Qualified)]
- [DefaultValue (FlagEnum.e1 | FlagEnum.e2)]
- public FlagEnum Flags3;
- [XmlAttribute ("flag4")]
- public FlagEnum Flags4;
- [XmlAttribute("modifiers")]
- public MapModifiers Modifiers;
- [XmlAttribute ("modifiers2", Form=XmlSchemaForm.Unqualified)]
- public MapModifiers Modifiers2;
- [XmlAttribute ("modifiers3")]
- [DefaultValue (0)]
- public MapModifiers Modifiers3;
- [XmlAttribute ("modifiers4", Form=XmlSchemaForm.Unqualified)]
- [DefaultValue (MapModifiers.Protected)]
- public MapModifiers Modifiers4;
- [XmlAttribute ("modifiers5", Form = XmlSchemaForm.Qualified)]
- [DefaultValue (MapModifiers.Public)]
- public MapModifiers Modifiers5;
- [XmlAttribute ("names")]
- public string[] Names;
- [XmlAttribute ("street")]
- public string Street;
- }
- [SoapType ("field", Namespace = "some:urn")]
- public class Field_Encoded
- {
- [SoapAttribute ("flag1")]
- [DefaultValue (FlagEnum_Encoded.e1)]
- public FlagEnum_Encoded Flags1;
- [SoapAttribute ("flag2")]
- [DefaultValue (FlagEnum_Encoded.e1)]
- public FlagEnum_Encoded Flags2;
- [SoapAttribute ("flag3")]
- [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e2)]
- public FlagEnum_Encoded Flags3;
- [SoapAttribute ("flag4")]
- public FlagEnum_Encoded Flags4;
- [SoapAttribute ("modifiers")]
- public MapModifiers Modifiers;
- [SoapAttribute ("modifiers2")]
- public MapModifiers Modifiers2;
- [SoapAttribute ("modifiers3")]
- [DefaultValue (MapModifiers.Public)]
- public MapModifiers Modifiers3;
- [SoapAttribute ("modifiers4")]
- [DefaultValue (MapModifiers.Protected)]
- public MapModifiers Modifiers4;
- [SoapAttribute ("modifiers5")]
- [DefaultValue (MapModifiers.Public)]
- public MapModifiers Modifiers5;
- public string[] Names;
- [SoapAttribute ("street")]
- public string Street;
- }
- [Flags]
- public enum MapModifiers
- {
- [XmlEnum("public")]
- Public = 0,
- [XmlEnum("protected")]
- Protected = 1,
- }
- public class MyList : ArrayList
- {
- object container;
-
- // NOTE: MyList has no public constructor
- public MyList (object container) : base()
- {
- this.container = container;
- }
- }
-
- public class Container
- {
- public MyList Items;
-
- public Container () {
- Items = new MyList(this);
- }
- }
-
- public class Container2
- {
- public MyList Items;
-
- public Container2 () {
- }
-
- public Container2 (bool b) {
- Items = new MyList(this);
- }
- }
- public class MyElem: XmlElement
- {
- public MyElem (XmlDocument doc): base ("","myelem","", doc)
- {
- SetAttribute ("aa","1");
- }
- [XmlAttribute]
- public int kk=1;
- }
- public class MyDocument: XmlDocument
- {
- public MyDocument ()
- {
- }
- [XmlAttribute]
- public int kk=1;
- }
-
- public class CDataContainer
- {
- public XmlCDataSection cdata;
- }
-
- public class NodeContainer
- {
- public XmlNode node;
- }
-
- public class Choices
- {
- [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
- [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]
- [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
- [XmlChoiceIdentifier("ItemType")]
- public string MyChoice;
- [XmlIgnore]
- public ItemChoiceType ItemType;
- }
-
- [XmlType(IncludeInSchema = false)]
- public enum ItemChoiceType
- {
- ChoiceZero,
- [XmlEnum ("ChoiceOne")]
- StrangeOne,
- ChoiceTwo,
- }
-
- public class WrongChoices
- {
- [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]
- [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]
- [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]
- [XmlChoiceIdentifier("ItemType")]
- public string MyChoice;
- [XmlIgnore]
- public ItemChoiceType ItemType;
- }
-
- [XmlType ("Type with space")]
- public class TestSpace
- {
- [XmlElement (ElementName = "Element with space")]
- public int elem;
-
- [XmlAttribute (AttributeName = "Attribute with space")]
- public int attr;
- }
- [Serializable]
- public class ReadOnlyProperties {
- string[] strArr = new string[2] { "string1", "string2" };
- public string[] StrArr {
- get { return strArr; }
- }
-
- public string dat {
- get { return "fff"; }
- }
- }
-
- [XmlRoot("root")]
- public class ListDefaults
- {
- public ListDefaults ()
- {
- ed = new SimpleClass ();
- str = "hola";
- }
-
- public ArrayList list2;
-
- public MyList list3;
-
- public string[] list4;
-
- [XmlElement("e", typeof(SimpleClass))]
- public ArrayList list5;
-
- [DefaultValue (null)]
- public SimpleClass ed;
-
- [DefaultValue (null)]
- public string str;
- }
-
- public class clsPerson
- {
- public IList EmailAccounts;
- }
-
- public class ArrayClass
- {
- public object names = new object[] { "un","dos" };
- }
-
- public class CompositeValueType
- {
- public void Init ()
- {
- Items = new object[] { 1, 2 };
- ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
- }
-
- [XmlElementAttribute("Es", typeof(int))]
- [XmlElementAttribute("In", typeof(int))]
- [XmlChoiceIdentifierAttribute("ItemsElementName")]
- public object[] Items;
-
- [XmlElementAttribute("ItemsElementName")]
- [XmlIgnoreAttribute()]
- public ItemsChoiceType[] ItemsElementName;
- }
- public enum ItemsChoiceType {
- In, Es
- }
-
- public class ArrayAttributeWithType
- {
- [XmlAttribute (DataType="anyURI")]
- public string[] at = new string [] { "a","b" };
- [XmlAttribute (DataType="base64Binary")]
- public byte[][] bin1 = new byte[][] { new byte[]{1,2}, new byte[]{1,2}};
-
- [XmlAttribute (DataType="base64Binary")]
- public byte[] bin2 = new byte[] { 1,2 };
- }
-
- public class ArrayAttributeWithWrongType
- {
- [XmlAttribute (DataType="int")]
- public string[] at = new string [] { "a","b" };
- }
-
- [XmlType ("Container")]
- public class EntityContainer
- {
- EntityCollection collection1;
- EntityCollection collection2;
- EntityCollection collection3 = new EntityCollection ("root");
- EntityCollection collection4 = new EntityCollection ("root");
-
- [XmlArray (IsNullable=true)]
- public EntityCollection Collection1 {
- get { return collection1; }
- set { collection1 = value; collection1.Container = "assigned"; }
- }
-
- [XmlArray (IsNullable=false)]
- public EntityCollection Collection2 {
- get { return collection2; }
- set { collection2 = value; collection2.Container = "assigned"; }
- }
-
- [XmlArray (IsNullable=true)]
- public EntityCollection Collection3 {
- get { return collection3; }
- set { collection3 = value; collection3.Container = "assigned"; }
- }
-
- [XmlArray (IsNullable=false)]
- public EntityCollection Collection4 {
- get { return collection4; }
- set { collection4 = value; collection4.Container = "assigned"; }
- }
- }
-
- [XmlType ("Container")]
- public class ArrayEntityContainer
- {
- Entity[] collection1;
- Entity[] collection2;
- Entity[] collection3 = new Entity [0];
- Entity[] collection4 = new Entity [0];
-
- [XmlArray (IsNullable=true)]
- public Entity[] Collection1 {
- get { return collection1; }
- set { collection1 = value; }
- }
-
- [XmlArray (IsNullable=false)]
- public Entity[] Collection2 {
- get { return collection2; }
- set { collection2 = value; }
- }
-
- [XmlArray (IsNullable=true)]
- public Entity[] Collection3 {
- get { return collection3; }
- set { collection3 = value; }
- }
-
- [XmlArray (IsNullable=false)]
- public Entity[] Collection4 {
- get { return collection4; }
- set { collection4 = value; }
- }
- }
-
- public class Entity
- {
- private string _name = string.Empty;
- private string _parent = null;
- [XmlAttribute]
- public string Name {
- get { return _name; }
- set { _name = value; }
- }
- [XmlIgnore]
- public string Parent {
- get { return _parent; }
- set { _parent = value; }
- }
- }
- public class EntityCollection : ArrayList
- {
- public string _container;
- public EntityCollection ()
- {
- }
- public EntityCollection (string c)
- {
- _container = c;
- }
- public string Container {
- get { return _container; }
- set { _container = value; }
- }
- public int Add (Entity value)
- {
- if(_container != null)
- value.Parent = _container;
- return base.Add(value);
- }
- public new Entity this[int index]
- {
- get { return (Entity) base[index]; }
- set { base[index] = value; }
- }
- }
-
- [XmlType ("Container")]
- public class ObjectWithReadonlyCollection
- {
- EntityCollection collection1 = new EntityCollection ("root");
-
- public EntityCollection Collection1 {
- get { return collection1; }
- }
- }
-
- [XmlType ("Container")]
- public class ObjectWithReadonlyNulCollection
- {
- EntityCollection collection1;
-
- public EntityCollection Collection1 {
- get { return collection1; }
- }
- }
-
- [XmlType ("Container")]
- public class ObjectWithReadonlyArray
- {
- Entity[] collection1 = new Entity [0];
-
- public Entity[] Collection1 {
- get { return collection1; }
- }
- }
-
- [XmlInclude (typeof(SubclassTestSub))]
- public class SubclassTestBase
- {
- }
-
- public class SubclassTestSub: SubclassTestBase
- {
- }
-
- public class SubclassTestExtra
- {
- }
-
- public class SubclassTestContainer
- {
- [XmlElement ("a", typeof(SubclassTestBase))]
- [XmlElement ("b", typeof(SubclassTestExtra))]
- public object data;
- }
- public class DictionaryWithIndexer : DictionaryBase
- {
- public TimeSpan this[int index] {
- get { return TimeSpan.MinValue; }
- }
- public void Add (TimeSpan value)
- {
- }
- }
- [XmlRoot(Namespace="some:urn")]
- [SoapTypeAttribute (Namespace="another:urn")]
- public class PrimitiveTypesContainer
- {
- public PrimitiveTypesContainer ()
- {
- Number = 2004;
- Name = "some name";
- Index = (byte) 56;
- Password = new byte[] { 243, 15 };
- PathSeparatorCharacter = '/';
- }
- public int Number;
- public string Name;
- public byte Index;
- public byte[] Password;
- public char PathSeparatorCharacter;
- }
-
- public class TestSchemaForm1
- {
- public PrintTypeResponse p1;
-
- [XmlElement(Namespace="urn:oo")]
- public PrintTypeResponse p2;
- }
- [XmlType (Namespace="urn:testForm")]
- public class TestSchemaForm2
- {
- public PrintTypeResponse p1;
-
- [XmlElement(Namespace="urn:oo")]
- public PrintTypeResponse p2;
- }
- [XmlType (Namespace="urn:responseTypes")]
- public class PrintTypeResponse {
- [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
- public OutputType result;
- public PrintTypeResponse intern;
-
- public void Init ()
- {
- result = new OutputType ();
- result.data = "data1";
- intern = new PrintTypeResponse ();
- intern.result = new OutputType ();
- intern.result.data = "data2";
- }
- }
- [XmlType (Namespace="urn:responseTypes")]
- public class OutputType {
-
- [XmlElement (Form=XmlSchemaForm.Unqualified, IsNullable=true)]
- public string data;
- }
- [XmlRootAttribute ("testDefault", Namespace="urn:myNS", IsNullable=false)]
- [SoapType("testDefault", Namespace="urn:myNS")]
- public class TestDefault
- {
- public string str;
- [DefaultValue ("Default Value")]
- public string strDefault = "Default Value";
- [DefaultValue (true)]
- public bool boolT = true;
- [DefaultValue (false)]
- public bool boolF = false;
- [DefaultValue (typeof (decimal), "10")]
- public decimal decimalval = 10m;
- [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
- public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
- [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
- public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
- }
- [XmlType ("optionalValueType", Namespace="some:urn")]
- [XmlRootAttribute ("optionalValue", Namespace="another:urn", IsNullable=false)]
- public class OptionalValueTypeContainer
- {
- [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
- public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
- [DefaultValue (FlagEnum.e1)]
- public FlagEnum Flags = FlagEnum.e1;
- [XmlIgnore]
- [SoapIgnore]
- public bool FlagsSpecified;
- [DefaultValue (false)]
- public bool IsEmpty;
- [XmlIgnore]
- [SoapIgnore]
- public bool IsEmptySpecified {
- get { return _isEmptySpecified; }
- set { _isEmptySpecified = value; }
- }
- [DefaultValue (false)]
- public bool IsNull;
- private bool _isEmptySpecified;
- }
- }
|