XmlSerializerTestClasses.cs 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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. public string[] StrArr
  361. {
  362. get { return strArr; }
  363. }
  364. public string dat
  365. {
  366. get { return "fff"; }
  367. }
  368. }
  369. [XmlRoot ("root")]
  370. public class ListDefaults
  371. {
  372. public ListDefaults ()
  373. {
  374. ed = new SimpleClass ();
  375. str = "hola";
  376. }
  377. public ArrayList list2;
  378. public MyList list3;
  379. public string[] list4;
  380. [XmlElement ("e", typeof (SimpleClass))]
  381. public ArrayList list5;
  382. [DefaultValue (null)]
  383. public SimpleClass ed;
  384. [DefaultValue (null)]
  385. public string str;
  386. }
  387. public class clsPerson
  388. {
  389. public IList EmailAccounts;
  390. }
  391. public class ArrayClass
  392. {
  393. public object names = new object[] { "un", "dos" };
  394. }
  395. public class CompositeValueType
  396. {
  397. public void Init ()
  398. {
  399. Items = new object[] { 1, 2 };
  400. ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
  401. }
  402. [XmlElementAttribute ("Es", typeof (int))]
  403. [XmlElementAttribute ("In", typeof (int))]
  404. [XmlChoiceIdentifierAttribute ("ItemsElementName")]
  405. public object[] Items;
  406. [XmlElementAttribute ("ItemsElementName")]
  407. [XmlIgnoreAttribute ()]
  408. public ItemsChoiceType[] ItemsElementName;
  409. }
  410. public enum ItemsChoiceType
  411. {
  412. In, Es
  413. }
  414. public class ArrayAttributeWithType
  415. {
  416. [XmlAttribute (DataType = "anyURI")]
  417. public string[] at = new string[] { "a", "b" };
  418. [XmlAttribute (DataType = "base64Binary")]
  419. public byte[][] bin1 = new byte[][] { new byte[] { 1, 2 }, new byte[] { 1, 2 } };
  420. [XmlAttribute (DataType = "base64Binary")]
  421. public byte[] bin2 = new byte[] { 1, 2 };
  422. }
  423. public class ArrayAttributeWithWrongType
  424. {
  425. [XmlAttribute (DataType = "int")]
  426. public string[] at = new string[] { "a", "b" };
  427. }
  428. [XmlType ("Container")]
  429. public class EntityContainer
  430. {
  431. EntityCollection collection1;
  432. EntityCollection collection2;
  433. EntityCollection collection3 = new EntityCollection ("root");
  434. EntityCollection collection4 = new EntityCollection ("root");
  435. [XmlArray (IsNullable = true)]
  436. public EntityCollection Collection1
  437. {
  438. get { return collection1; }
  439. set { collection1 = value; collection1.Container = "assigned"; }
  440. }
  441. [XmlArray (IsNullable = false)]
  442. public EntityCollection Collection2
  443. {
  444. get { return collection2; }
  445. set { collection2 = value; collection2.Container = "assigned"; }
  446. }
  447. [XmlArray (IsNullable = true)]
  448. public EntityCollection Collection3
  449. {
  450. get { return collection3; }
  451. set { collection3 = value; collection3.Container = "assigned"; }
  452. }
  453. [XmlArray (IsNullable = false)]
  454. public EntityCollection Collection4
  455. {
  456. get { return collection4; }
  457. set { collection4 = value; collection4.Container = "assigned"; }
  458. }
  459. }
  460. [XmlType ("Container")]
  461. public class ArrayEntityContainer
  462. {
  463. Entity[] collection1;
  464. Entity[] collection2;
  465. Entity[] collection3 = new Entity[0];
  466. Entity[] collection4 = new Entity[0];
  467. [XmlArray (IsNullable = true)]
  468. public Entity[] Collection1
  469. {
  470. get { return collection1; }
  471. set { collection1 = value; }
  472. }
  473. [XmlArray (IsNullable = false)]
  474. public Entity[] Collection2
  475. {
  476. get { return collection2; }
  477. set { collection2 = value; }
  478. }
  479. [XmlArray (IsNullable = true)]
  480. public Entity[] Collection3
  481. {
  482. get { return collection3; }
  483. set { collection3 = value; }
  484. }
  485. [XmlArray (IsNullable = false)]
  486. public Entity[] Collection4
  487. {
  488. get { return collection4; }
  489. set { collection4 = value; }
  490. }
  491. }
  492. public class Entity
  493. {
  494. private string _name = string.Empty;
  495. private string _parent = null;
  496. [XmlAttribute]
  497. public string Name
  498. {
  499. get { return _name; }
  500. set { _name = value; }
  501. }
  502. [XmlIgnore]
  503. public string Parent
  504. {
  505. get { return _parent; }
  506. set { _parent = value; }
  507. }
  508. }
  509. public class EntityCollection : ArrayList
  510. {
  511. public string _container;
  512. public EntityCollection ()
  513. {
  514. }
  515. public EntityCollection (string c)
  516. {
  517. _container = c;
  518. }
  519. public string Container
  520. {
  521. get { return _container; }
  522. set { _container = value; }
  523. }
  524. public int Add (Entity value)
  525. {
  526. if (_container != null)
  527. value.Parent = _container;
  528. return base.Add (value);
  529. }
  530. public new Entity this[int index]
  531. {
  532. get { return (Entity) base[index]; }
  533. set { base[index] = value; }
  534. }
  535. }
  536. [XmlType ("Container")]
  537. public class ObjectWithReadonlyCollection
  538. {
  539. EntityCollection collection1 = new EntityCollection ("root");
  540. public EntityCollection Collection1
  541. {
  542. get { return collection1; }
  543. }
  544. }
  545. [XmlType ("Container")]
  546. public class ObjectWithReadonlyNulCollection
  547. {
  548. EntityCollection collection1;
  549. public EntityCollection Collection1
  550. {
  551. get { return collection1; }
  552. }
  553. }
  554. [XmlType ("Container")]
  555. public class ObjectWithReadonlyArray
  556. {
  557. Entity[] collection1 = new Entity[0];
  558. public Entity[] Collection1
  559. {
  560. get { return collection1; }
  561. }
  562. }
  563. [XmlInclude (typeof (SubclassTestSub))]
  564. public class SubclassTestBase
  565. {
  566. }
  567. public class SubclassTestSub : SubclassTestBase
  568. {
  569. }
  570. public class SubclassTestExtra
  571. {
  572. }
  573. public class SubclassTestContainer
  574. {
  575. [XmlElement ("a", typeof (SubclassTestBase))]
  576. [XmlElement ("b", typeof (SubclassTestExtra))]
  577. public object data;
  578. }
  579. public class DictionaryWithIndexer : DictionaryBase
  580. {
  581. public TimeSpan this[int index]
  582. {
  583. get { return TimeSpan.MinValue; }
  584. }
  585. public void Add (TimeSpan value)
  586. {
  587. }
  588. }
  589. [XmlRoot (Namespace = "some:urn")]
  590. [SoapTypeAttribute (Namespace = "another:urn")]
  591. public class PrimitiveTypesContainer
  592. {
  593. public PrimitiveTypesContainer ()
  594. {
  595. Number = 2004;
  596. Name = "some name";
  597. Index = (byte) 56;
  598. Password = new byte[] { 243, 15 };
  599. PathSeparatorCharacter = '/';
  600. }
  601. public int Number;
  602. public string Name;
  603. public byte Index;
  604. public byte[] Password;
  605. public char PathSeparatorCharacter;
  606. }
  607. public class TestSchemaForm1
  608. {
  609. public PrintTypeResponse p1;
  610. [XmlElement (Namespace = "urn:oo")]
  611. public PrintTypeResponse p2;
  612. }
  613. [XmlType (Namespace = "urn:testForm")]
  614. public class TestSchemaForm2
  615. {
  616. public PrintTypeResponse p1;
  617. [XmlElement (Namespace = "urn:oo")]
  618. public PrintTypeResponse p2;
  619. }
  620. [XmlType (Namespace = "urn:responseTypes")]
  621. public class PrintTypeResponse
  622. {
  623. [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
  624. public OutputType result;
  625. public PrintTypeResponse intern;
  626. public void Init ()
  627. {
  628. result = new OutputType ();
  629. result.data = "data1";
  630. intern = new PrintTypeResponse ();
  631. intern.result = new OutputType ();
  632. intern.result.data = "data2";
  633. }
  634. }
  635. [XmlType (Namespace = "urn:responseTypes")]
  636. public class OutputType
  637. {
  638. [XmlElement (Form = XmlSchemaForm.Unqualified, IsNullable = true)]
  639. public string data;
  640. }
  641. [XmlRootAttribute ("testDefault", Namespace = "urn:myNS", IsNullable = false)]
  642. [SoapType ("testDefault", Namespace = "urn:myNS")]
  643. public class TestDefault
  644. {
  645. public string str;
  646. [DefaultValue ("Default Value")]
  647. public string strDefault = "Default Value";
  648. [DefaultValue (true)]
  649. public bool boolT = true;
  650. [DefaultValue (false)]
  651. public bool boolF = false;
  652. [DefaultValue (typeof (decimal), "10")]
  653. public decimal decimalval = 10m;
  654. [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
  655. public FlagEnum flag = (FlagEnum.e1 | FlagEnum.e4);
  656. [DefaultValue (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4)]
  657. public FlagEnum_Encoded flagencoded = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4);
  658. }
  659. [XmlType ("optionalValueType", Namespace = "some:urn")]
  660. [XmlRootAttribute ("optionalValue", Namespace = "another:urn", IsNullable = false)]
  661. public class OptionalValueTypeContainer
  662. {
  663. [DefaultValue (FlagEnum.e1 | FlagEnum.e4)]
  664. public FlagEnum Attributes = FlagEnum.e1 | FlagEnum.e4;
  665. [DefaultValue (FlagEnum.e1)]
  666. public FlagEnum Flags = FlagEnum.e1;
  667. [XmlIgnore]
  668. [SoapIgnore]
  669. public bool FlagsSpecified;
  670. [DefaultValue (false)]
  671. public bool IsEmpty;
  672. [XmlIgnore]
  673. [SoapIgnore]
  674. public bool IsEmptySpecified
  675. {
  676. get { return _isEmptySpecified; }
  677. set { _isEmptySpecified = value; }
  678. }
  679. [DefaultValue (false)]
  680. public bool IsNull;
  681. private bool _isEmptySpecified;
  682. }
  683. public class Group
  684. {
  685. [SoapAttribute (Namespace = "http://www.cpandl.com")]
  686. public string GroupName;
  687. [SoapAttribute (DataType = "base64Binary")]
  688. public Byte[] GroupNumber;
  689. [SoapAttribute (DataType = "date", AttributeName = "CreationDate")]
  690. public DateTime Today;
  691. [SoapElement (DataType = "nonNegativeInteger", ElementName = "PosInt")]
  692. public string PostitiveInt;
  693. [SoapIgnore]
  694. public bool IgnoreThis;
  695. [DefaultValue (GroupType.B)]
  696. public GroupType Grouptype;
  697. public Vehicle MyVehicle;
  698. [SoapInclude (typeof (Car))]
  699. public Vehicle myCar (string licNumber)
  700. {
  701. Vehicle v;
  702. if (licNumber == string.Empty) {
  703. v = new Car ();
  704. v.licenseNumber = "!!!!!!";
  705. }
  706. else {
  707. v = new Car ();
  708. v.licenseNumber = licNumber;
  709. }
  710. return v;
  711. }
  712. }
  713. [SoapInclude (typeof (Car))]
  714. public abstract class Vehicle
  715. {
  716. public string licenseNumber;
  717. [SoapElement (DataType = "date")]
  718. public DateTime makeDate;
  719. [DefaultValue ("450")]
  720. public string weight;
  721. }
  722. public class Car : Vehicle
  723. {
  724. }
  725. public enum GroupType
  726. {
  727. [SoapEnum ("Small")]
  728. A,
  729. [SoapEnum ("Large")]
  730. B
  731. }
  732. public class ErrorneousGetSchema : IXmlSerializable
  733. {
  734. public XmlSchema GetSchema ()
  735. {
  736. throw new ApplicationException ("unexpected");
  737. }
  738. public void ReadXml (XmlReader reader)
  739. {
  740. }
  741. public void WriteXml (XmlWriter writer)
  742. {
  743. }
  744. // it should be serialized IF it is NOT IXmlSerializable.
  745. public string Whoa = "whoa";
  746. }
  747. [XmlRoot ("DefaultDateTimeContainer", Namespace = "urn:foo")]
  748. public class DefaultDateTimeContainer // bug #378696
  749. {
  750. public DateTime SimpleDateTime;
  751. [DefaultValue(typeof(DateTime), "2001-02-03T04:05:06")]
  752. public DateTime FancyDateTime;
  753. [DefaultValue (typeof (int), "123456")]
  754. public int Numeric;
  755. }
  756. public class XmlSerializableImplicitConvertible
  757. {
  758. public BaseClass B = new DerivedClass ();
  759. public class XmlSerializable : IXmlSerializable
  760. {
  761. public void WriteXml (XmlWriter writer)
  762. {
  763. }
  764. public void ReadXml (XmlReader reader)
  765. {
  766. }
  767. public XmlSchema GetSchema ()
  768. {
  769. return null;
  770. }
  771. }
  772. public class BaseClass
  773. {
  774. public static implicit operator XmlSerializable (BaseClass b)
  775. {
  776. return new XmlSerializable ();
  777. }
  778. public static implicit operator BaseClass (XmlSerializable x)
  779. {
  780. return new BaseClass ();
  781. }
  782. }
  783. public class DerivedClass : BaseClass
  784. {
  785. }
  786. }
  787. public class Bug704813Type
  788. {
  789. IEnumerable<string> foo = new List<string> ();
  790. public IEnumerable<string> Foo {
  791. get { return foo; }
  792. }
  793. }
  794. public class Bug708178Type
  795. {
  796. List<string> foo = new List<string> ();
  797. [XmlArray("Foo"), XmlArrayItem("Foo", typeof(string))]
  798. public List<string> Foo {
  799. get { return foo; }
  800. }
  801. }
  802. [XmlRoot("root")]
  803. public class ExplicitlyOrderedMembersType1
  804. {
  805. [XmlElement("child0", Order = 4)]
  806. public string Child0;
  807. [XmlElement("child", Order = 0)]
  808. public string Child1;
  809. [XmlElement("child", Order = 2)]
  810. public string Child2;
  811. }
  812. [XmlRoot("root")]
  813. public class ExplicitlyOrderedMembersType2
  814. {
  815. [XmlElement("child0", Order = 4)]
  816. public string Child0;
  817. [XmlElement("child")] // wrong. Needs to be Ordered as well.
  818. public string Child1;
  819. [XmlElement("child", Order = 2)]
  820. public string Child2;
  821. }
  822. [XmlRoot("root")]
  823. public class ExplicitlyOrderedMembersType3
  824. {
  825. [XmlElement("child0", Order = 1)] // it's between 0 and 2. After two "child" elements, child0 is not recognized as this member.
  826. public string Child0;
  827. [XmlElement("child", Order = 0)]
  828. public string Child1;
  829. [XmlElement("child", Order = 2)]
  830. public string Child2;
  831. }
  832. }