2
0

XmlSerializerTestClasses.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. //
  2. // System.Xml.XmlSerializerTestClasses
  3. //
  4. // Authors:
  5. // Erik LeBel <[email protected]>
  6. // Hagit Yidov <[email protected]>
  7. //
  8. // (C) 2003 Erik LeBel
  9. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  10. //
  11. // Classes to use in the testing of the XmlSerializer
  12. //
  13. using System;
  14. using System.Collections;
  15. #if NET_2_0
  16. using System.Collections.Generic;
  17. #endif
  18. using System.ComponentModel;
  19. using System.Xml;
  20. using System.Xml.Schema;
  21. using System.Xml.Serialization;
  22. namespace MonoTests.System.Xml.TestClasses
  23. {
  24. public enum SimpleEnumeration { FIRST, SECOND };
  25. [Flags]
  26. public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }
  27. public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }
  28. [Flags]
  29. public enum FlagEnum
  30. {
  31. [XmlEnum ("one")]
  32. e1 = 1,
  33. [XmlEnum ("two")]
  34. e2 = 2,
  35. [XmlEnum ("four")]
  36. e4 = 4
  37. }
  38. [Flags]
  39. [SoapType ("flagenum")]
  40. public enum FlagEnum_Encoded
  41. {
  42. [SoapEnum ("one")]
  43. e1 = 1,
  44. [SoapEnum ("two")]
  45. e2 = 2,
  46. [SoapEnum ("four")]
  47. e4 = 4
  48. }
  49. [Flags]
  50. public enum ZeroFlagEnum
  51. {
  52. [XmlEnum ("zero")]
  53. e0 = 0,
  54. [XmlEnum ("o<n>e")]
  55. e1 = 1,
  56. [XmlEnum ("tns:t<w>o")]
  57. e2 = 2,
  58. [XmlEnum ("four")]
  59. [XmlIgnore]
  60. e4 = 4
  61. }
  62. #region GenericsTestClasses
  63. #if NET_2_0
  64. public class GenSimpleClass<T>
  65. {
  66. public T something = default (T);
  67. }
  68. public struct GenSimpleStruct<T>
  69. {
  70. public T something;
  71. public GenSimpleStruct (int dummy)
  72. {
  73. something = default (T);
  74. }
  75. }
  76. public class GenListClass<T>
  77. {
  78. public List<T> somelist = new List<T> ();
  79. }
  80. public class GenArrayClass<T>
  81. {
  82. public T[] arr = new T[3];
  83. }
  84. public class GenTwoClass<T1, T2>
  85. {
  86. public T1 something1 = default (T1);
  87. public T2 something2 = default (T2);
  88. }
  89. public class GenDerivedClass<T1, T2> : GenTwoClass<string, int>
  90. {
  91. public T1 another1 = default (T1);
  92. public T2 another2 = default (T2);
  93. }
  94. public class GenDerived2Class<T1, T2> : GenTwoClass<T1, T2>
  95. {
  96. public T1 another1 = default (T1);
  97. public T2 another2 = default (T2);
  98. }
  99. public class GenNestedClass<TO, TI>
  100. {
  101. public TO outer = default (TO);
  102. public class InnerClass<T>
  103. {
  104. public TI inner = default (TI);
  105. public T something = default (T);
  106. }
  107. }
  108. public struct GenComplexStruct<T1, T2>
  109. {
  110. public T1 something;
  111. public GenSimpleClass<T1> simpleclass;
  112. public GenSimpleStruct<T1> simplestruct;
  113. public GenListClass<T1> listclass;
  114. public GenArrayClass<T1> arrayclass;
  115. public GenTwoClass<T1, T2> twoclass;
  116. public GenDerivedClass<T1, T2> derivedclass;
  117. public GenDerived2Class<T1, T2> derived2;
  118. public GenNestedClass<T1, T2> nestedouter;
  119. public GenNestedClass<T1, T2>.InnerClass<T1> nestedinner;
  120. public GenComplexStruct (int dummy)
  121. {
  122. something = default (T1);
  123. simpleclass = new GenSimpleClass<T1> ();
  124. simplestruct = new GenSimpleStruct<T1> ();
  125. listclass = new GenListClass<T1> ();
  126. arrayclass = new GenArrayClass<T1> ();
  127. twoclass = new GenTwoClass<T1, T2> ();
  128. derivedclass = new GenDerivedClass<T1, T2> ();
  129. derived2 = new GenDerived2Class<T1, T2> ();
  130. nestedouter = new GenNestedClass<T1, T2> ();
  131. nestedinner = new GenNestedClass<T1, T2>.InnerClass<T1> ();
  132. }
  133. }
  134. public class WithNulls
  135. {
  136. [XmlElement (IsNullable=true)]
  137. public int? nint;
  138. [XmlElement (IsNullable=true)]
  139. public TestEnumWithNulls? nenum;
  140. [XmlElement (IsNullable=true)]
  141. public DateTime? ndate;
  142. }
  143. public enum TestEnumWithNulls
  144. {
  145. aa,
  146. bb
  147. }
  148. #endif
  149. #endregion // GenericsTestClasses
  150. public class SimpleClass
  151. {
  152. public string something = null;
  153. }
  154. public class StringCollection : CollectionBase
  155. {
  156. public void Add (String parameter)
  157. {
  158. List.Insert (Count, parameter);
  159. }
  160. public String this[int index]
  161. {
  162. get
  163. {
  164. if (index < 0 || index > Count)
  165. throw new ArgumentOutOfRangeException ();
  166. return (String) List[index];
  167. }
  168. set { List[index] = value; }
  169. }
  170. }
  171. public class StringCollectionContainer
  172. {
  173. StringCollection messages = new StringCollection ();
  174. public StringCollection Messages
  175. {
  176. get { return messages; }
  177. }
  178. }
  179. public class ArrayContainer
  180. {
  181. public object[] items = null;
  182. }
  183. public class ClassArrayContainer
  184. {
  185. public SimpleClass[] items = null;
  186. }
  187. [XmlRoot ("simple")]
  188. public class SimpleClassWithXmlAttributes
  189. {
  190. [XmlAttribute ("member")]
  191. public string something = null;
  192. }
  193. [XmlRoot ("field")]
  194. public class Field
  195. {
  196. [XmlAttribute ("flag1")]
  197. [DefaultValue (1)]
  198. public FlagEnum Flags1;
  199. [XmlAttribute ("flag2")]
  200. [DefaultValue (FlagEnum.e1)]
  201. public FlagEnum Flags2;
  202. [XmlAttribute ("flag3", Form = XmlSchemaForm.Qualified)]
  203. [DefaultValue (FlagEnum.e1 | FlagEnum.e2)]
  204. public FlagEnum Flags3;
  205. [XmlAttribute ("flag4")]
  206. public FlagEnum Flags4;
  207. [XmlAttribute ("modifiers")]
  208. public MapModifiers Modifiers;
  209. [XmlAttribute ("modifiers2", Form = XmlSchemaForm.Unqualified)]
  210. public MapModifiers Modifiers2;
  211. [XmlAttribute ("modifiers3")]
  212. [DefaultValue (0)]
  213. public MapModifiers Modifiers3;
  214. [XmlAttribute ("modifiers4", Form = XmlSchemaForm.Unqualified)]
  215. [DefaultValue (MapModifiers.Protected)]
  216. public MapModifiers Modifiers4;
  217. [XmlAttribute ("modifiers5", Form = XmlSchemaForm.Qualified)]
  218. [DefaultValue (MapModifiers.Public)]
  219. public MapModifiers Modifiers5;
  220. [XmlAttribute ("names")]
  221. public string[] Names;
  222. [XmlAttribute ("street")]
  223. public string Street;
  224. }
  225. [SoapType ("field", Namespace = "some:urn")]
  226. public class Field_Encoded
  227. {
  228. [SoapAttribute ("flag1")]
  229. [DefaultValue (FlagEnum_Encoded.e1)]
  230. public FlagEnum_Encoded Flags1;
  231. [SoapAttribute ("flag2")]
  232. [DefaultValue (FlagEnum_Encoded.e1)]
  233. public FlagEnum_Encoded Flags2;
  234. [SoapAttribute ("flag3")]
  235. [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e2)]
  236. public FlagEnum_Encoded Flags3;
  237. [SoapAttribute ("flag4")]
  238. public FlagEnum_Encoded Flags4;
  239. [SoapAttribute ("modifiers")]
  240. public MapModifiers Modifiers;
  241. [SoapAttribute ("modifiers2")]
  242. public MapModifiers Modifiers2;
  243. [SoapAttribute ("modifiers3")]
  244. [DefaultValue (MapModifiers.Public)]
  245. public MapModifiers Modifiers3;
  246. [SoapAttribute ("modifiers4")]
  247. [DefaultValue (MapModifiers.Protected)]
  248. public MapModifiers Modifiers4;
  249. [SoapAttribute ("modifiers5")]
  250. [DefaultValue (MapModifiers.Public)]
  251. public MapModifiers Modifiers5;
  252. public string[] Names;
  253. [SoapAttribute ("street")]
  254. public string Street;
  255. }
  256. [Flags]
  257. public enum MapModifiers
  258. {
  259. [XmlEnum ("public")]
  260. [SoapEnum ("PuBlIc")]
  261. Public = 0,
  262. [XmlEnum ("protected")]
  263. Protected = 1,
  264. }
  265. public class MyList : ArrayList
  266. {
  267. object container;
  268. // NOTE: MyList has no public constructor
  269. public MyList (object container)
  270. : base ()
  271. {
  272. this.container = container;
  273. }
  274. }
  275. public class Container
  276. {
  277. public MyList Items;
  278. public Container ()
  279. {
  280. Items = new MyList (this);
  281. }
  282. }
  283. public class Container2
  284. {
  285. public MyList Items;
  286. public Container2 ()
  287. {
  288. }
  289. public Container2 (bool b)
  290. {
  291. Items = new MyList (this);
  292. }
  293. }
  294. public class MyElem : XmlElement
  295. {
  296. public MyElem (XmlDocument doc)
  297. : base ("", "myelem", "", doc)
  298. {
  299. SetAttribute ("aa", "1");
  300. }
  301. [XmlAttribute]
  302. public int kk = 1;
  303. }
  304. public class MyDocument : XmlDocument
  305. {
  306. public MyDocument ()
  307. {
  308. }
  309. [XmlAttribute]
  310. public int kk = 1;
  311. }
  312. public class CDataContainer
  313. {
  314. public XmlCDataSection cdata;
  315. }
  316. public class NodeContainer
  317. {
  318. public XmlNode node;
  319. }
  320. public class Choices
  321. {
  322. [XmlElementAttribute ("ChoiceZero", typeof (string), IsNullable = false)]
  323. [XmlElementAttribute ("ChoiceOne", typeof (string), IsNullable = false)]
  324. [XmlElementAttribute ("ChoiceTwo", typeof (string), IsNullable = false)]
  325. [XmlChoiceIdentifier ("ItemType")]
  326. public string MyChoice;
  327. [XmlIgnore]
  328. public ItemChoiceType ItemType;
  329. }
  330. [XmlType (IncludeInSchema = false)]
  331. public enum ItemChoiceType
  332. {
  333. ChoiceZero,
  334. [XmlEnum ("ChoiceOne")]
  335. StrangeOne,
  336. ChoiceTwo,
  337. }
  338. public class WrongChoices
  339. {
  340. [XmlElementAttribute ("ChoiceZero", typeof (string), IsNullable = false)]
  341. [XmlElementAttribute ("StrangeOne", typeof (string), IsNullable = false)]
  342. [XmlElementAttribute ("ChoiceTwo", typeof (string), IsNullable = false)]
  343. [XmlChoiceIdentifier ("ItemType")]
  344. public string MyChoice;
  345. [XmlIgnore]
  346. public ItemChoiceType ItemType;
  347. }
  348. [XmlType ("Type with space")]
  349. public class TestSpace
  350. {
  351. [XmlElement (ElementName = "Element with space")]
  352. public int elem;
  353. [XmlAttribute (AttributeName = "Attribute with space")]
  354. public int attr;
  355. }
  356. [Serializable]
  357. public class ReadOnlyProperties
  358. {
  359. string[] strArr = new string[2] { "string1", "string2" };
  360. List<string> strList = new List<string> { "listString1" };
  361. public string[] StrArr
  362. {
  363. get { return strArr; }
  364. }
  365. public string dat
  366. {
  367. get { return "fff"; }
  368. }
  369. public IList<string> StrList { get { return strList; } }
  370. }
  371. [Serializable]
  372. public class ReadOnlyListProperty {
  373. List<string> strList = new List<string> { "listString1", "listString2" };
  374. public List<string> StrList
  375. {
  376. get { return strList; }
  377. }
  378. }
  379. [XmlRoot ("root")]
  380. public class ListDefaults
  381. {
  382. public ListDefaults ()
  383. {
  384. ed = new SimpleClass ();
  385. str = "hola";
  386. }
  387. public ArrayList list2;
  388. public MyList list3;
  389. public string[] list4;
  390. [XmlElement ("e", typeof (SimpleClass))]
  391. public ArrayList list5;
  392. [DefaultValue (null)]
  393. public SimpleClass ed;
  394. [DefaultValue (null)]
  395. public string str;
  396. }
  397. public class clsPerson
  398. {
  399. public IList EmailAccounts;
  400. }
  401. public class ArrayClass
  402. {
  403. public object names = new object[] { "un", "dos" };
  404. }
  405. public class CompositeValueType
  406. {
  407. public void Init ()
  408. {
  409. Items = new object[] { 1, 2 };
  410. ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
  411. }
  412. [XmlElementAttribute ("Es", typeof (int))]
  413. [XmlElementAttribute ("In", typeof (int))]
  414. [XmlChoiceIdentifierAttribute ("ItemsElementName")]
  415. public object[] Items;
  416. [XmlElementAttribute ("ItemsElementName")]
  417. [XmlIgnoreAttribute ()]
  418. public ItemsChoiceType[] ItemsElementName;
  419. }
  420. public enum ItemsChoiceType
  421. {
  422. In, Es
  423. }
  424. public class ArrayAttributeWithType
  425. {
  426. [XmlAttribute (DataType = "anyURI")]
  427. public string[] at = new string[] { "a", "b" };
  428. [XmlAttribute (DataType = "base64Binary")]
  429. public byte[][] bin1 = new byte[][] { new byte[] { 1, 2 }, new byte[] { 1, 2 } };
  430. [XmlAttribute (DataType = "base64Binary")]
  431. public byte[] bin2 = new byte[] { 1, 2 };
  432. }
  433. public class ArrayAttributeWithWrongType
  434. {
  435. [XmlAttribute (DataType = "int")]
  436. public string[] at = new string[] { "a", "b" };
  437. }
  438. [XmlType ("Container")]
  439. public class EntityContainer
  440. {
  441. EntityCollection collection1;
  442. EntityCollection collection2;
  443. EntityCollection collection3 = new EntityCollection ("root");
  444. EntityCollection collection4 = new EntityCollection ("root");
  445. [XmlArray (IsNullable = true)]
  446. public EntityCollection Collection1
  447. {
  448. get { return collection1; }
  449. set { collection1 = value; collection1.Container = "assigned"; }
  450. }
  451. [XmlArray (IsNullable = false)]
  452. public EntityCollection Collection2
  453. {
  454. get { return collection2; }
  455. set { collection2 = value; collection2.Container = "assigned"; }
  456. }
  457. [XmlArray (IsNullable = true)]
  458. public EntityCollection Collection3
  459. {
  460. get { return collection3; }
  461. set { collection3 = value; collection3.Container = "assigned"; }
  462. }
  463. [XmlArray (IsNullable = false)]
  464. public EntityCollection Collection4
  465. {
  466. get { return collection4; }
  467. set { collection4 = value; collection4.Container = "assigned"; }
  468. }
  469. }
  470. [XmlType ("Container")]
  471. public class ArrayEntityContainer
  472. {
  473. Entity[] collection1;
  474. Entity[] collection2;
  475. Entity[] collection3 = new Entity[0];
  476. Entity[] collection4 = new Entity[0];
  477. [XmlArray (IsNullable = true)]
  478. public Entity[] Collection1
  479. {
  480. get { return collection1; }
  481. set { collection1 = value; }
  482. }
  483. [XmlArray (IsNullable = false)]
  484. public Entity[] Collection2
  485. {
  486. get { return collection2; }
  487. set { collection2 = value; }
  488. }
  489. [XmlArray (IsNullable = true)]
  490. public Entity[] Collection3
  491. {
  492. get { return collection3; }
  493. set { collection3 = value; }
  494. }
  495. [XmlArray (IsNullable = false)]
  496. public Entity[] Collection4
  497. {
  498. get { return collection4; }
  499. set { collection4 = value; }
  500. }
  501. }
  502. public class Entity
  503. {
  504. private string _name = string.Empty;
  505. private string _parent = null;
  506. [XmlAttribute]
  507. public string Name
  508. {
  509. get { return _name; }
  510. set { _name = value; }
  511. }
  512. [XmlIgnore]
  513. public string Parent
  514. {
  515. get { return _parent; }
  516. set { _parent = value; }
  517. }
  518. }
  519. public class EntityCollection : ArrayList
  520. {
  521. public string _container;
  522. public EntityCollection ()
  523. {
  524. }
  525. public EntityCollection (string c)
  526. {
  527. _container = c;
  528. }
  529. public string Container
  530. {
  531. get { return _container; }
  532. set { _container = value; }
  533. }
  534. public int Add (Entity value)
  535. {
  536. if (_container != null)
  537. value.Parent = _container;
  538. return base.Add (value);
  539. }
  540. public new Entity this[int index]
  541. {
  542. get { return (Entity) base[index]; }
  543. set { base[index] = value; }
  544. }
  545. }
  546. [XmlType ("Container")]
  547. public class ObjectWithReadonlyCollection
  548. {
  549. EntityCollection collection1 = new EntityCollection ("root");
  550. public EntityCollection Collection1
  551. {
  552. get { return collection1; }
  553. }
  554. }
  555. [XmlType ("Container")]
  556. public class ObjectWithReadonlyNulCollection
  557. {
  558. EntityCollection collection1;
  559. public EntityCollection Collection1
  560. {
  561. get { return collection1; }
  562. }
  563. }
  564. [XmlType ("Container")]
  565. public class ObjectWithReadonlyArray
  566. {
  567. Entity[] collection1 = new Entity[0];
  568. public Entity[] Collection1
  569. {
  570. get { return collection1; }
  571. }
  572. }
  573. [XmlInclude (typeof (SubclassTestSub))]
  574. public class SubclassTestBase
  575. {
  576. }
  577. public class SubclassTestSub : SubclassTestBase
  578. {
  579. }
  580. public class SubclassTestExtra
  581. {
  582. }
  583. public class SubclassTestContainer
  584. {
  585. [XmlElement ("a", typeof (SubclassTestBase))]
  586. [XmlElement ("b", typeof (SubclassTestExtra))]
  587. public object data;
  588. }
  589. public class DictionaryWithIndexer : DictionaryBase
  590. {
  591. public TimeSpan this[int index]
  592. {
  593. get { return TimeSpan.MinValue; }
  594. }
  595. public void Add (TimeSpan value)
  596. {
  597. }
  598. }
  599. [XmlRoot (Namespace = "some:urn")]
  600. [SoapTypeAttribute (Namespace = "another:urn")]
  601. public class PrimitiveTypesContainer
  602. {
  603. public PrimitiveTypesContainer ()
  604. {
  605. Number = 2004;
  606. Name = "some name";
  607. Index = (byte) 56;
  608. Password = new byte[] { 243, 15 };
  609. PathSeparatorCharacter = '/';
  610. }
  611. public int Number;
  612. public string Name;
  613. public byte Index;
  614. public byte[] Password;
  615. public char PathSeparatorCharacter;
  616. }
  617. public class TestSchemaForm1
  618. {
  619. public PrintTypeResponse p1;
  620. [XmlElement (Namespace = "urn:oo")]
  621. public PrintTypeResponse p2;
  622. }
  623. [XmlType (Namespace = "urn:testForm")]
  624. public class TestSchemaForm2
  625. {
  626. public PrintTypeResponse p1;
  627. [XmlElement (Namespace = "urn:oo")]
  628. public PrintTypeResponse p2;
  629. }
  630. [XmlType (Namespace = "urn:responseTypes")]
  631. public class PrintTypeResponse
  632. {
  633. [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
  634. public OutputType result;
  635. public PrintTypeResponse intern;
  636. public void Init ()
  637. {
  638. result = new OutputType ();
  639. result.data = "data1";
  640. intern = new PrintTypeResponse ();
  641. intern.result = new OutputType ();
  642. intern.result.data = "data2";
  643. }
  644. }
  645. [XmlType (Namespace = "urn:responseTypes")]
  646. public class OutputType
  647. {
  648. [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
  649. public string data;
  650. }
  651. [XmlRootAttribute ("testDefault", Namespace = "urn:myNS", IsNullable = false)]
  652. [SoapType ("testDefault", Namespace = "urn:myNS")]
  653. public class TestDefault
  654. {
  655. public string str;
  656. [DefaultValue ("Default Value")]
  657. public string strDefault = "Default Value";
  658. [DefaultValue (true)]
  659. public bool boolT = true;
  660. [DefaultValue (false)]
  661. public bool boolF = false;
  662. [DefaultValue (typeof (decimal), "10")]
  663. public decimal decimalval = 10m;
  664. [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
  665. public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
  666. [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
  667. public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
  668. }
  669. [XmlType ("optionalValueType", Namespace = "some:urn")]
  670. [XmlRootAttribute ("optionalValue", Namespace = "another:urn", IsNullable = false)]
  671. public class OptionalValueTypeContainer
  672. {
  673. [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
  674. public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
  675. [DefaultValue (FlagEnum.e1)]
  676. public FlagEnum Flags = FlagEnum.e1;
  677. [XmlIgnore]
  678. [SoapIgnore]
  679. public bool FlagsSpecified;
  680. [DefaultValue (false)]
  681. public bool IsEmpty;
  682. [XmlIgnore]
  683. [SoapIgnore]
  684. public bool IsEmptySpecified
  685. {
  686. get { return _isEmptySpecified; }
  687. set { _isEmptySpecified = value; }
  688. }
  689. [DefaultValue (false)]
  690. public bool IsNull;
  691. private bool _isEmptySpecified;
  692. }
  693. public class Group
  694. {
  695. [SoapAttribute (Namespace = "http://www.cpandl.com")]
  696. public string GroupName;
  697. [SoapAttribute (DataType = "base64Binary")]
  698. public Byte[] GroupNumber;
  699. [SoapAttribute (DataType = "date", AttributeName = "CreationDate")]
  700. public DateTime Today;
  701. [SoapElement (DataType = "nonNegativeInteger", ElementName = "PosInt")]
  702. public string PostitiveInt;
  703. [SoapIgnore]
  704. public bool IgnoreThis;
  705. [DefaultValue (GroupType.B)]
  706. public GroupType Grouptype;
  707. public Vehicle MyVehicle;
  708. [SoapInclude (typeof (Car))]
  709. public Vehicle myCar (string licNumber)
  710. {
  711. Vehicle v;
  712. if (licNumber == string.Empty) {
  713. v = new Car ();
  714. v.licenseNumber = "!!!!!!";
  715. }
  716. else {
  717. v = new Car ();
  718. v.licenseNumber = licNumber;
  719. }
  720. return v;
  721. }
  722. }
  723. [SoapInclude (typeof (Car))]
  724. public abstract class Vehicle
  725. {
  726. public string licenseNumber;
  727. [SoapElement (DataType = "date")]
  728. public DateTime makeDate;
  729. [DefaultValue ("450")]
  730. public string weight;
  731. }
  732. public class Car : Vehicle
  733. {
  734. }
  735. public enum GroupType
  736. {
  737. [SoapEnum ("Small")]
  738. A,
  739. [SoapEnum ("Large")]
  740. B
  741. }
  742. public class ErrorneousGetSchema : IXmlSerializable
  743. {
  744. public XmlSchema GetSchema ()
  745. {
  746. throw new ApplicationException ("unexpected");
  747. }
  748. public void ReadXml (XmlReader reader)
  749. {
  750. }
  751. public void WriteXml (XmlWriter writer)
  752. {
  753. }
  754. // it should be serialized IF it is NOT IXmlSerializable.
  755. public string Whoa = "whoa";
  756. }
  757. [XmlRoot ("DefaultDateTimeContainer", Namespace = "urn:foo")]
  758. public class DefaultDateTimeContainer // bug #378696
  759. {
  760. public DateTime SimpleDateTime;
  761. [DefaultValue(typeof(DateTime), "2001-02-03T04:05:06")]
  762. public DateTime FancyDateTime;
  763. [DefaultValue (typeof (int), "123456")]
  764. public int Numeric;
  765. }
  766. public class XmlSerializableImplicitConvertible
  767. {
  768. public BaseClass B = new DerivedClass ();
  769. public class XmlSerializable : IXmlSerializable
  770. {
  771. public void WriteXml (XmlWriter writer)
  772. {
  773. }
  774. public void ReadXml (XmlReader reader)
  775. {
  776. }
  777. public XmlSchema GetSchema ()
  778. {
  779. return null;
  780. }
  781. }
  782. public class BaseClass
  783. {
  784. public static implicit operator XmlSerializable (BaseClass b)
  785. {
  786. return new XmlSerializable ();
  787. }
  788. public static implicit operator BaseClass (XmlSerializable x)
  789. {
  790. return new BaseClass ();
  791. }
  792. }
  793. public class DerivedClass : BaseClass
  794. {
  795. }
  796. }
  797. public class Bug704813Type
  798. {
  799. IEnumerable<string> foo = new List<string> ();
  800. public IEnumerable<string> Foo {
  801. get { return foo; }
  802. }
  803. }
  804. public class Bug708178Type
  805. {
  806. List<string> foo = new List<string> ();
  807. [XmlArray("Foo"), XmlArrayItem("Foo", typeof(string))]
  808. public List<string> Foo {
  809. get { return foo; }
  810. }
  811. }
  812. [XmlRoot("root")]
  813. public class ExplicitlyOrderedMembersType1
  814. {
  815. [XmlElement("child0", Order = 4)]
  816. public string Child0;
  817. [XmlElement("child", Order = 0)]
  818. public string Child1;
  819. [XmlElement("child", Order = 2)]
  820. public string Child2;
  821. }
  822. [XmlRoot("root")]
  823. public class ExplicitlyOrderedMembersType2
  824. {
  825. [XmlElement("child0", Order = 4)]
  826. public string Child0;
  827. [XmlElement("child")] // wrong. Needs to be Ordered as well.
  828. public string Child1;
  829. [XmlElement("child", Order = 2)]
  830. public string Child2;
  831. }
  832. [XmlRoot("root")]
  833. public class ExplicitlyOrderedMembersType3
  834. {
  835. [XmlElement("child0", Order = 1)] // it's between 0 and 2. After two "child" elements, child0 is not recognized as this member.
  836. public string Child0;
  837. [XmlElement("child", Order = 0)]
  838. public string Child1;
  839. [XmlElement("child", Order = 2)]
  840. public string Child2;
  841. }
  842. [XmlRoot("root")]
  843. public class ExplicitlyOrderedMembersType4
  844. {
  845. [XmlElement("child0", Order = 1)] // it's between 0 and 2. After two "child" elements, child0 is not recognized as this member.
  846. public string Child0;
  847. [XmlElement("child", Order = 0)]
  848. public string Child1;
  849. [XmlElement("child", Order = 2)]
  850. public string Child2;
  851. [XmlAttribute]
  852. public string Child3;
  853. }
  854. [XmlRoot ("root")]
  855. public class NullableDatesAndTimes {
  856. [XmlElementAttribute ("MyTime", DataType = "time", IsNullable = false)]
  857. public DateTime MyTime;
  858. [XmlElementAttribute ("MyTimeNullable", DataType = "time", IsNullable = true)]
  859. public DateTime? MyTimeNullable;
  860. [XmlElementAttribute ("MyDate", DataType = "date", IsNullable = false)]
  861. public DateTime MyDate;
  862. [XmlElementAttribute ("MyDateNullable", DataType = "date", IsNullable = true)]
  863. public DateTime? MyDateNullable;
  864. }
  865. public class NotExactDateParseClass
  866. {
  867. [XmlElementAttribute (DataType = "date")]
  868. public DateTime SomeDate;
  869. }
  870. public class Bug8468BaseClass
  871. {
  872. public string Base;
  873. }
  874. public class Bug8468MidClass: Bug8468BaseClass
  875. {
  876. public string Mid;
  877. }
  878. [XmlRoot("Test", Namespace="http://test-namespace")]
  879. public class Bug8468Subclass: Bug8468MidClass
  880. {
  881. }
  882. [XmlRoot("Test")]
  883. public class Bug8468SubclassNoNamespace: Bug8468MidClass
  884. {
  885. }
  886. [XmlRoot("Test", Namespace="")]
  887. public class Bug8468BaseClassV2
  888. {
  889. public string Base;
  890. }
  891. public class Bug8468MidClassV2: Bug8468BaseClassV2
  892. {
  893. public string Mid;
  894. }
  895. [XmlRoot("Test", Namespace="http://test-namespace")]
  896. public class Bug8468SubclassV2: Bug8468MidClassV2
  897. {
  898. }
  899. [XmlRoot("Test")]
  900. public class Bug8468SubclassNoNamespaceV2: Bug8468MidClassV2
  901. {
  902. }
  903. [XmlRoot("Test")]
  904. public class Bug9193Class
  905. {
  906. [XmlElement ("Data", Order=0)]
  907. public string[] Data;
  908. [XmlElement ("Extra", Order=1)]
  909. public string[] Extra;
  910. }
  911. public class SimpleObjectA
  912. {
  913. [XmlAttribute]
  914. public string Text
  915. {
  916. get; set;
  917. }
  918. public static implicit operator SimpleObjectA (SimpleObjectB o)
  919. {
  920. return new SimpleObjectA { Text = o.Text };
  921. }
  922. public static implicit operator SimpleObjectB (SimpleObjectA o)
  923. {
  924. return new SimpleObjectB { Text = o.Text };
  925. }
  926. }
  927. public class SimpleObjectB
  928. {
  929. [XmlAttribute]
  930. public string Text
  931. {
  932. get; set;
  933. }
  934. }
  935. public class ObjectWithElementRequiringImplicitCast
  936. {
  937. public ObjectWithElementRequiringImplicitCast () { }
  938. public ObjectWithElementRequiringImplicitCast (string text)
  939. {
  940. Object = new SimpleObjectB { Text = text };
  941. }
  942. [XmlElement(Type = typeof (SimpleObjectA))]
  943. public SimpleObjectB Object
  944. {
  945. get; set;
  946. }
  947. }
  948. }