XmlSerializerTestClasses.cs 23 KB

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