XmlCodeExporterTests.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. //
  2. // System.Xml.Serialization.XmlCodeExporterTests
  3. //
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (C) 2006 Novell
  8. //
  9. using System;
  10. using System.CodeDom;
  11. using System.CodeDom.Compiler;
  12. using System.Collections;
  13. using System.Globalization;
  14. using System.IO;
  15. using System.Xml;
  16. using System.Xml.Schema;
  17. using System.Xml.Serialization;
  18. using Microsoft.CSharp;
  19. using NUnit.Framework;
  20. using MonoTests.System.Xml.TestClasses;
  21. namespace MonoTests.System.XmlSerialization
  22. {
  23. [TestFixture]
  24. public class XmlCodeExporterTests
  25. {
  26. [Test]
  27. public void ExportTypeMapping_ArrayClass ()
  28. {
  29. CodeNamespace codeNamespace = ExportCode (typeof (ArrayClass));
  30. Assert.IsNotNull (codeNamespace, "#1");
  31. StringWriter sw = new StringWriter ();
  32. CodeDomProvider provider = new CSharpCodeProvider ();
  33. ICodeGenerator generator = provider.CreateGenerator ();
  34. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  35. Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
  36. "{0}{0}" +
  37. "/// <remarks/>{0}" +
  38. #if NET_2_0
  39. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  40. "[System.SerializableAttribute()]{0}" +
  41. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  42. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  43. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  44. "public partial class ArrayClass {{{0}" +
  45. " {0}" +
  46. " private object namesField;{0}" +
  47. " {0}" +
  48. " /// <remarks/>{0}" +
  49. " public object names {{{0}" +
  50. " get {{{0}" +
  51. " return this.namesField;{0}" +
  52. " }}{0}" +
  53. " set {{{0}" +
  54. " this.namesField = value;{0}" +
  55. " }}{0}" +
  56. " }}{0}" +
  57. #else
  58. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  59. "public class ArrayClass {{{0}" +
  60. " {0}" +
  61. " /// <remarks/>{0}" +
  62. " public object names;{0}" +
  63. #endif
  64. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  65. codeNamespace = ExportCode (typeof (ArrayClass[]));
  66. Assert.IsNotNull (codeNamespace, "#3");
  67. sw.GetStringBuilder ().Length = 0;
  68. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  69. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  70. "{0}{0}" +
  71. "/// <remarks/>{0}" +
  72. #if NET_2_0
  73. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  74. "[System.SerializableAttribute()]{0}" +
  75. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  76. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  77. "public partial class ArrayClass {{{0}" +
  78. " {0}" +
  79. " private object namesField;{0}" +
  80. " {0}" +
  81. " /// <remarks/>{0}" +
  82. " public object names {{{0}" +
  83. " get {{{0}" +
  84. " return this.namesField;{0}" +
  85. " }}{0}" +
  86. " set {{{0}" +
  87. " this.namesField = value;{0}" +
  88. " }}{0}" +
  89. " }}{0}" +
  90. #else
  91. "public class ArrayClass {{{0}" +
  92. " {0}" +
  93. " /// <remarks/>{0}" +
  94. " public object names;{0}" +
  95. #endif
  96. "}}{0}", Environment.NewLine), sw.ToString (), "#4");
  97. }
  98. [Test]
  99. public void ExportTypeMapping_ArrayContainer ()
  100. {
  101. CodeNamespace codeNamespace = ExportCode (typeof (ArrayContainer));
  102. Assert.IsNotNull (codeNamespace, "#1");
  103. StringWriter sw = new StringWriter ();
  104. CodeDomProvider provider = new CSharpCodeProvider ();
  105. ICodeGenerator generator = provider.CreateGenerator ();
  106. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  107. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  108. "{0}{0}" +
  109. "/// <remarks/>{0}" +
  110. #if NET_2_0
  111. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  112. "[System.SerializableAttribute()]{0}" +
  113. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  114. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  115. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  116. "public partial class ArrayContainer {{{0}" +
  117. " {0}" +
  118. " private object[] itemsField;{0}" +
  119. " {0}" +
  120. " /// <remarks/>{0}" +
  121. " public object[] items {{{0}" +
  122. " get {{{0}" +
  123. " return this.itemsField;{0}" +
  124. " }}{0}" +
  125. " set {{{0}" +
  126. " this.itemsField = value;{0}" +
  127. " }}{0}" +
  128. " }}{0}" +
  129. #else
  130. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  131. "public class ArrayContainer {{{0}" +
  132. " {0}" +
  133. " /// <remarks/>{0}" +
  134. " public object[] items;{0}" +
  135. #endif
  136. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  137. }
  138. [Test]
  139. public void ExportTypeMapping_CDataContainer ()
  140. {
  141. CodeNamespace codeNamespace = ExportCode (typeof (CDataContainer));
  142. Assert.IsNotNull (codeNamespace, "#1");
  143. StringWriter sw = new StringWriter ();
  144. CodeDomProvider provider = new CSharpCodeProvider ();
  145. ICodeGenerator generator = provider.CreateGenerator ();
  146. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  147. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  148. "{0}{0}" +
  149. "/// <remarks/>{0}" +
  150. #if NET_2_0
  151. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  152. "[System.SerializableAttribute()]{0}" +
  153. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  154. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  155. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  156. "public partial class CDataContainer {{{0}" +
  157. " {0}" +
  158. " private System.Xml.XmlCDataSection cdataField;{0}" +
  159. " {0}" +
  160. " /// <remarks/>{0}" +
  161. " public System.Xml.XmlCDataSection cdata {{{0}" +
  162. " get {{{0}" +
  163. " return this.cdataField;{0}" +
  164. " }}{0}" +
  165. " set {{{0}" +
  166. " this.cdataField = value;{0}" +
  167. " }}{0}" +
  168. " }}{0}" +
  169. #else
  170. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  171. "public class CDataContainer {{{0}" +
  172. " {0}" +
  173. " /// <remarks/>{0}" +
  174. " public System.Xml.XmlCDataSection cdata;{0}" +
  175. #endif
  176. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  177. }
  178. [Test]
  179. [Category ("NotWorking")] // order of XmlElementAttribute's does not match that of MSFT
  180. [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
  181. public void ExportTypeMapping_Choices ()
  182. {
  183. CodeNamespace codeNamespace = ExportCode (typeof (Choices));
  184. Assert.IsNotNull (codeNamespace, "#1");
  185. StringWriter sw = new StringWriter ();
  186. CodeDomProvider provider = new CSharpCodeProvider ();
  187. ICodeGenerator generator = provider.CreateGenerator ();
  188. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  189. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  190. "{0}{0}" +
  191. "/// <remarks/>{0}" +
  192. #if NET_2_0
  193. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  194. "[System.SerializableAttribute()]{0}" +
  195. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  196. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  197. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  198. "public partial class Choices {{{0}" +
  199. " {0}" +
  200. " private string myChoiceField;{0}" +
  201. " {0}" +
  202. " /// <remarks/>{0}" +
  203. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
  204. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
  205. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
  206. " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
  207. " public string MyChoice {{{0}" +
  208. " get {{{0}" +
  209. " return this.myChoiceField;{0}" +
  210. " }}{0}" +
  211. " set {{{0}" +
  212. " this.myChoiceField = value;{0}" +
  213. " }}{0}" +
  214. " }}{0}" +
  215. #else
  216. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  217. "public class Choices {{{0}" +
  218. " {0}" +
  219. " /// <remarks/>{0}" +
  220. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
  221. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
  222. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
  223. " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
  224. " public string MyChoice;{0}" +
  225. #endif
  226. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  227. }
  228. [Test]
  229. #if NET_2_0
  230. [Category ("NotDotNet")] // regression in MS.NET 2.0
  231. #endif
  232. [Category ("NotWorking")] // TODO: order of DefaultValueAttribute, ...
  233. public void ExportTypeMapping_Field ()
  234. {
  235. CodeNamespace codeNamespace = ExportCode (typeof (Field));
  236. Assert.IsNotNull (codeNamespace, "#1");
  237. StringWriter sw = new StringWriter ();
  238. CodeDomProvider provider = new CSharpCodeProvider ();
  239. ICodeGenerator generator = provider.CreateGenerator ();
  240. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  241. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  242. "{0}{0}" +
  243. "/// <remarks/>{0}" +
  244. #if NET_2_0
  245. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  246. "[System.SerializableAttribute()]{0}" +
  247. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  248. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  249. "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
  250. "public partial class Field {{{0}" +
  251. " {0}" +
  252. " private MonoTests.System.Xml.TestClasses.FlagEnum flags1Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
  253. " {0}" +
  254. " private MonoTests.System.Xml.TestClasses.FlagEnum flags2Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
  255. " {0}" +
  256. " private MonoTests.System.Xml.TestClasses.FlagEnum flags3Field = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
  257. " {0}" +
  258. " private MonoTests.System.Xml.TestClasses.FlagEnum flags4Field;{0}" +
  259. " {0}" +
  260. " private MonoTests.System.Xml.TestClasses.MapModifiers modifiersField;{0}" +
  261. " {0}" +
  262. " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers2Field;{0}" +
  263. " {0}" +
  264. " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers3Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  265. " {0}" +
  266. " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers4Field = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
  267. " {0}" +
  268. " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers5Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  269. " {0}" +
  270. " private string[] namesField;{0}" +
  271. " {0}" +
  272. " private string streetField;{0}" +
  273. " {0}" +
  274. " /// <remarks/>{0}" +
  275. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
  276. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
  277. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 {{{0}" +
  278. " get {{{0}" +
  279. " return this.flags1Field;{0}" +
  280. " }}{0}" +
  281. " set {{{0}" +
  282. " this.flags1Field = value;{0}" +
  283. " }}{0}" +
  284. " }}{0}" +
  285. " {0}" +
  286. " /// <remarks/>{0}" +
  287. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
  288. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
  289. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 {{{0}" +
  290. " get {{{0}" +
  291. " return this.flags2Field;{0}" +
  292. " }}{0}" +
  293. " set {{{0}" +
  294. " this.flags2Field = value;{0}" +
  295. " }}{0}" +
  296. " }}{0}" +
  297. " {0}" +
  298. " /// <remarks/>{0}" +
  299. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
  300. " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
  301. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 {{{0}" +
  302. " get {{{0}" +
  303. " return this.flags3Field;{0}" +
  304. " }}{0}" +
  305. " set {{{0}" +
  306. " this.flags3Field = value;{0}" +
  307. " }}{0}" +
  308. " }}{0}" +
  309. " {0}" +
  310. " /// <remarks/>{0}" +
  311. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
  312. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags4 {{{0}" +
  313. " get {{{0}" +
  314. " return this.flags4Field;{0}" +
  315. " }}{0}" +
  316. " set {{{0}" +
  317. " this.flags4Field = value;{0}" +
  318. " }}{0}" +
  319. " }}{0}" +
  320. " {0}" +
  321. " /// <remarks/>{0}" +
  322. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
  323. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers {{{0}" +
  324. " get {{{0}" +
  325. " return this.modifiersField;{0}" +
  326. " }}{0}" +
  327. " set {{{0}" +
  328. " this.modifiersField = value;{0}" +
  329. " }}{0}" +
  330. " }}{0}" +
  331. " {0}" +
  332. " /// <remarks/>{0}" +
  333. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
  334. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2 {{{0}" +
  335. " get {{{0}" +
  336. " return this.modifiers2Field;{0}" +
  337. " }}{0}" +
  338. " set {{{0}" +
  339. " this.modifiers2Field = value;{0}" +
  340. " }}{0}" +
  341. " }}{0}" +
  342. " {0}" +
  343. " /// <remarks/>{0}" +
  344. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
  345. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  346. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 {{{0}" +
  347. " get {{{0}" +
  348. " return this.modifiers3Field;{0}" +
  349. " }}{0}" +
  350. " set {{{0}" +
  351. " this.modifiers3Field = value;{0}" +
  352. " }}{0}" +
  353. " }}{0}" +
  354. " {0}" +
  355. " /// <remarks/>{0}" +
  356. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
  357. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
  358. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 {{{0}" +
  359. " get {{{0}" +
  360. " return this.modifiers4Field;{0}" +
  361. " }}{0}" +
  362. " set {{{0}" +
  363. " this.modifiers4Field = value;{0}" +
  364. " }}{0}" +
  365. " }}{0}" +
  366. " {0}" +
  367. " /// <remarks/>{0}" +
  368. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
  369. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  370. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 {{{0}" +
  371. " get {{{0}" +
  372. " return this.modifiers5Field;{0}" +
  373. " }}{0}" +
  374. " set {{{0}" +
  375. " this.modifiers5Field = value;{0}" +
  376. " }}{0}" +
  377. " }}{0}" +
  378. " {0}" +
  379. " /// <remarks/>{0}" +
  380. " [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
  381. " public string[] Names {{{0}" +
  382. " get {{{0}" +
  383. " return this.namesField;{0}" +
  384. " }}{0}" +
  385. " set {{{0}" +
  386. " this.namesField = value;{0}" +
  387. " }}{0}" +
  388. " }}{0}" +
  389. " {0}" +
  390. " /// <remarks/>{0}" +
  391. " [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
  392. " public string Street {{{0}" +
  393. " get {{{0}" +
  394. " return this.streetField;{0}" +
  395. " }}{0}" +
  396. " set {{{0}" +
  397. " this.streetField = value;{0}" +
  398. " }}{0}" +
  399. " }}{0}" +
  400. #else
  401. "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
  402. "public class Field {{{0}" +
  403. " {0}" +
  404. " /// <remarks/>{0}" +
  405. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
  406. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
  407. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
  408. " {0}" +
  409. " /// <remarks/>{0}" +
  410. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
  411. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
  412. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
  413. " {0}" +
  414. " /// <remarks/>{0}" +
  415. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
  416. " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
  417. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
  418. " {0}" +
  419. " /// <remarks/>{0}" +
  420. " [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
  421. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags4;{0}" +
  422. " {0}" +
  423. " /// <remarks/>{0}" +
  424. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
  425. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers;{0}" +
  426. " {0}" +
  427. " /// <remarks/>{0}" +
  428. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
  429. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2;{0}" +
  430. " {0}" +
  431. " /// <remarks/>{0}" +
  432. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
  433. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  434. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  435. " {0}" +
  436. " /// <remarks/>{0}" +
  437. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
  438. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
  439. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
  440. " {0}" +
  441. " /// <remarks/>{0}" +
  442. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
  443. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  444. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  445. " {0}" +
  446. " /// <remarks/>{0}" +
  447. " [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
  448. " public string[] Names;{0}" +
  449. " {0}" +
  450. " /// <remarks/>{0}" +
  451. " [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
  452. " public string Street;{0}" +
  453. #endif
  454. "}}{0}" +
  455. "{0}" +
  456. "/// <remarks/>{0}" +
  457. "[System.FlagsAttribute()]{0}" +
  458. #if NET_2_0
  459. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  460. "[System.SerializableAttribute()]{0}" +
  461. #endif
  462. "public enum FlagEnum {{{0}" +
  463. " {0}" +
  464. " /// <remarks/>{0}" +
  465. " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
  466. " e1 = 1,{0}" +
  467. " {0}" +
  468. " /// <remarks/>{0}" +
  469. " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
  470. " e2 = 2,{0}" +
  471. " {0}" +
  472. " /// <remarks/>{0}" +
  473. " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
  474. " e4 = 4,{0}" +
  475. "}}{0}" +
  476. "{0}" +
  477. "/// <remarks/>{0}" +
  478. "[System.FlagsAttribute()]{0}" +
  479. #if NET_2_0
  480. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  481. "[System.SerializableAttribute()]{0}" +
  482. #endif
  483. "public enum MapModifiers {{{0}" +
  484. " {0}" +
  485. " /// <remarks/>{0}" +
  486. " [System.Xml.Serialization.XmlEnumAttribute(\"public\")]{0}" +
  487. " Public = 1,{0}" +
  488. " {0}" +
  489. " /// <remarks/>{0}" +
  490. " [System.Xml.Serialization.XmlEnumAttribute(\"protected\")]{0}" +
  491. " Protected = 2,{0}" +
  492. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  493. }
  494. [Test]
  495. public void ExportTypeMapping_ItemChoiceType ()
  496. {
  497. CodeNamespace codeNamespace = ExportCode (typeof (ItemChoiceType));
  498. Assert.IsNotNull (codeNamespace, "#1");
  499. StringWriter sw = new StringWriter ();
  500. CodeDomProvider provider = new CSharpCodeProvider ();
  501. ICodeGenerator generator = provider.CreateGenerator ();
  502. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  503. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  504. "{0}{0}" +
  505. "/// <remarks/>{0}" +
  506. #if NET_2_0
  507. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  508. "[System.SerializableAttribute()]{0}" +
  509. #endif
  510. "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
  511. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
  512. "public enum ItemChoiceType {{{0}" +
  513. " {0}" +
  514. " /// <remarks/>{0}" +
  515. " ChoiceZero,{0}" +
  516. " {0}" +
  517. " /// <remarks/>{0}" +
  518. " [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
  519. " StrangeOne,{0}" +
  520. " {0}" +
  521. " /// <remarks/>{0}" +
  522. " ChoiceTwo,{0}" +
  523. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  524. codeNamespace = ExportCode (typeof (ItemChoiceType[]));
  525. Assert.IsNotNull (codeNamespace, "#3");
  526. sw.GetStringBuilder ().Length = 0;
  527. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  528. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  529. "{0}{0}" +
  530. "/// <remarks/>{0}" +
  531. #if NET_2_0
  532. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  533. "[System.SerializableAttribute()]{0}" +
  534. #endif
  535. "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
  536. "public enum ItemChoiceType {{{0}" +
  537. " {0}" +
  538. " /// <remarks/>{0}" +
  539. " ChoiceZero,{0}" +
  540. " {0}" +
  541. " /// <remarks/>{0}" +
  542. " [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
  543. " StrangeOne,{0}" +
  544. " {0}" +
  545. " /// <remarks/>{0}" +
  546. " ChoiceTwo,{0}" +
  547. "}}{0}", Environment.NewLine), sw.ToString (), "#4");
  548. }
  549. [Test]
  550. public void ExportTypeMapping_ClassArrayContainer ()
  551. {
  552. CodeNamespace codeNamespace = ExportCode (typeof (ClassArrayContainer));
  553. Assert.IsNotNull (codeNamespace, "#1");
  554. StringWriter sw = new StringWriter ();
  555. CodeDomProvider provider = new CSharpCodeProvider ();
  556. ICodeGenerator generator = provider.CreateGenerator ();
  557. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  558. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  559. "{0}{0}" +
  560. "/// <remarks/>{0}" +
  561. #if NET_2_0
  562. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  563. "[System.SerializableAttribute()]{0}" +
  564. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  565. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  566. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  567. "public partial class ClassArrayContainer {{{0}" +
  568. " {0}" +
  569. " private MonoTests.System.Xml.TestClasses.SimpleClass[] itemsField;{0}" +
  570. " {0}" +
  571. " /// <remarks/>{0}" +
  572. " public MonoTests.System.Xml.TestClasses.SimpleClass[] items {{{0}" +
  573. " get {{{0}" +
  574. " return this.itemsField;{0}" +
  575. " }}{0}" +
  576. " set {{{0}" +
  577. " this.itemsField = value;{0}" +
  578. " }}{0}" +
  579. " }}{0}" +
  580. "}}{0}" +
  581. "{0}" +
  582. "/// <remarks/>{0}" +
  583. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  584. "[System.SerializableAttribute()]{0}" +
  585. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  586. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  587. "public partial class SimpleClass {{{0}" +
  588. " {0}" +
  589. " private string somethingField;{0}" +
  590. " {0}" +
  591. " /// <remarks/>{0}" +
  592. " public string something {{{0}" +
  593. " get {{{0}" +
  594. " return this.somethingField;{0}" +
  595. " }}{0}" +
  596. " set {{{0}" +
  597. " this.somethingField = value;{0}" +
  598. " }}{0}" +
  599. " }}{0}" +
  600. #else
  601. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  602. "public class ClassArrayContainer {{{0}" +
  603. " {0}" +
  604. " /// <remarks/>{0}" +
  605. " public MonoTests.System.Xml.TestClasses.SimpleClass[] items;{0}" +
  606. "}}{0}" +
  607. "{0}" +
  608. "/// <remarks/>{0}" +
  609. "public class SimpleClass {{{0}" +
  610. " {0}" +
  611. " /// <remarks/>{0}" +
  612. " public string something;{0}" +
  613. #endif
  614. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  615. }
  616. [Test]
  617. #if NET_2_0
  618. [Category ("NotDotNet")] // regression in MS.NET 2.0
  619. #endif
  620. [Category ("NotWorking")] // bug #78214
  621. public void ExportTypeMapping_Root ()
  622. {
  623. CodeNamespace codeNamespace = ExportCode (typeof (Root));
  624. Assert.IsNotNull (codeNamespace, "#1");
  625. StringWriter sw = new StringWriter ();
  626. CodeDomProvider provider = new CSharpCodeProvider ();
  627. ICodeGenerator generator = provider.CreateGenerator ();
  628. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  629. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  630. "{0}{0}" +
  631. "/// <remarks/>{0}" +
  632. "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
  633. "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
  634. "public class Root {{{0}" +
  635. " {0}" +
  636. " /// <remarks/>{0}" +
  637. " public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue;{0}" +
  638. " {0}" +
  639. " /// <remarks/>{0}" +
  640. " public MonoTests.System.Xml.TestClasses.TestDefault Default;{0}" +
  641. "}}{0}" +
  642. "{0}" +
  643. "/// <remarks/>{0}" +
  644. "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
  645. "public class OptionalValueTypeContainer {{{0}" +
  646. " {0}" +
  647. " /// <remarks/>{0}" +
  648. " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
  649. " public MonoTests.System.Xml.TestClasses.FlagEnum Attributes = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
  650. " {0}" +
  651. " /// <remarks/>{0}" +
  652. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
  653. " public MonoTests.System.Xml.TestClasses.FlagEnum Flags = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
  654. " {0}" +
  655. " /// <remarks/>{0}" +
  656. " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
  657. " public bool FlagsSpecified;{0}" +
  658. " {0}" +
  659. " /// <remarks/>{0}" +
  660. " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
  661. " public bool IsEmpty = false;{0}" +
  662. " {0}" +
  663. " /// <remarks/>{0}" +
  664. " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
  665. " public bool IsEmptySpecified;{0}" +
  666. " {0}" +
  667. " /// <remarks/>{0}" +
  668. " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
  669. " public bool IsNull = false;{0}" +
  670. "}}{0}" +
  671. "{0}" +
  672. "/// <remarks/>{0}" +
  673. "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
  674. "[System.FlagsAttribute()]{0}" +
  675. "public enum FlagEnum {{{0}" +
  676. " {0}" +
  677. " /// <remarks/>{0}" +
  678. " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
  679. " e1 = 1,{0}" +
  680. " {0}" +
  681. " /// <remarks/>{0}" +
  682. " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
  683. " e2 = 2,{0}" +
  684. " {0}" +
  685. " /// <remarks/>{0}" +
  686. " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
  687. " e4 = 4,{0}" +
  688. "}}{0}" +
  689. "{0}" +
  690. "/// <remarks/>{0}" +
  691. "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
  692. "public class TestDefault {{{0}" +
  693. " {0}" +
  694. " /// <remarks/>{0}" +
  695. " public string str;{0}" +
  696. " {0}" +
  697. " /// <remarks/>{0}" +
  698. " [System.ComponentModel.DefaultValueAttribute(\"Default Value\")]{0}" +
  699. " public string strDefault = \"Default Value\";{0}" +
  700. " {0}" +
  701. " /// <remarks/>{0}" +
  702. " [System.ComponentModel.DefaultValueAttribute(true)]{0}" +
  703. " public bool boolT = true;{0}" +
  704. " {0}" +
  705. " /// <remarks/>{0}" +
  706. " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
  707. " public bool boolF = false;{0}" +
  708. " {0}" +
  709. " /// <remarks/>{0}" +
  710. " [System.ComponentModel.DefaultValueAttribute(typeof(System.Decimal), \"10\")]{0}" +
  711. " public System.Decimal decimalval = ((System.Decimal)(10m));{0}" +
  712. " {0}" +
  713. " /// <remarks/>{0}" +
  714. " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
  715. " public MonoTests.System.Xml.TestClasses.FlagEnum flag = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
  716. " {0}" +
  717. " /// <remarks/>{0}" +
  718. " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4))]{0}" +
  719. " public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
  720. "}}{0}" +
  721. "{0}" +
  722. "/// <remarks/>{0}" +
  723. "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
  724. "[System.FlagsAttribute()]{0}" +
  725. "public enum FlagEnum {{{0}" +
  726. " {0}" +
  727. " /// <remarks/>{0}" +
  728. " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
  729. " e1 = 1,{0}" +
  730. " {0}" +
  731. " /// <remarks/>{0}" +
  732. " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
  733. " e2 = 2,{0}" +
  734. " {0}" +
  735. " /// <remarks/>{0}" +
  736. " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
  737. " e4 = 4,{0}" +
  738. "}}{0}" +
  739. "{0}" +
  740. "/// <remarks/>{0}" +
  741. "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
  742. "[System.FlagsAttribute()]{0}" +
  743. "public enum FlagEnum_Encoded {{{0}" +
  744. " {0}" +
  745. " /// <remarks/>{0}" +
  746. " e1 = 1,{0}" +
  747. " {0}" +
  748. " /// <remarks/>{0}" +
  749. " e2 = 2,{0}" +
  750. " {0}" +
  751. " /// <remarks/>{0}" +
  752. " e4 = 4,{0}" +
  753. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  754. }
  755. [Test]
  756. public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
  757. {
  758. CodeNamespace codeNamespace = ExportCode (typeof (SimpleClassWithXmlAttributes));
  759. Assert.IsNotNull (codeNamespace, "#1");
  760. StringWriter sw = new StringWriter ();
  761. CodeDomProvider provider = new CSharpCodeProvider ();
  762. ICodeGenerator generator = provider.CreateGenerator ();
  763. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  764. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  765. "{0}{0}" +
  766. "/// <remarks/>{0}" +
  767. #if NET_2_0
  768. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  769. "[System.SerializableAttribute()]{0}" +
  770. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  771. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  772. "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
  773. "public partial class SimpleClassWithXmlAttributes {{{0}" +
  774. " {0}" +
  775. " private string somethingField;{0}" +
  776. " {0}" +
  777. " /// <remarks/>{0}" +
  778. " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
  779. " public string something {{{0}" +
  780. " get {{{0}" +
  781. " return this.somethingField;{0}" +
  782. " }}{0}" +
  783. " set {{{0}" +
  784. " this.somethingField = value;{0}" +
  785. " }}{0}" +
  786. " }}{0}" +
  787. #else
  788. "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
  789. "public class SimpleClassWithXmlAttributes {{{0}" +
  790. " {0}" +
  791. " /// <remarks/>{0}" +
  792. " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
  793. " public string something;{0}" +
  794. #endif
  795. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  796. }
  797. [Test]
  798. public void ExportTypeMapping_XsdPrimitive_Arrays ()
  799. {
  800. ArrayList types = new ArrayList ();
  801. types.Add (typeof (sbyte[]));
  802. types.Add (typeof (bool[]));
  803. types.Add (typeof (short[]));
  804. types.Add (typeof (int[]));
  805. types.Add (typeof (long[]));
  806. types.Add (typeof (float[]));
  807. types.Add (typeof (double[]));
  808. types.Add (typeof (decimal[]));
  809. types.Add (typeof (ushort[]));
  810. types.Add (typeof (uint[]));
  811. types.Add (typeof (ulong[]));
  812. types.Add (typeof (DateTime[]));
  813. types.Add (typeof (XmlQualifiedName[]));
  814. types.Add (typeof (string[]));
  815. StringWriter sw = new StringWriter ();
  816. CodeDomProvider provider = new CSharpCodeProvider ();
  817. ICodeGenerator generator = provider.CreateGenerator ();
  818. foreach (Type type in types) {
  819. CodeNamespace codeNamespace = ExportCode (type);
  820. Assert.IsNotNull (codeNamespace, type.FullName + "#1");
  821. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  822. Assert.AreEqual (Environment.NewLine, sw.ToString (),
  823. type.FullName + "#2");
  824. sw.GetStringBuilder ().Length = 0;
  825. }
  826. }
  827. [Test]
  828. public void ExportTypeMapping_ZeroFlagEnum ()
  829. {
  830. CodeNamespace codeNamespace = ExportCode (typeof (ZeroFlagEnum));
  831. Assert.IsNotNull (codeNamespace, "#1");
  832. StringWriter sw = new StringWriter ();
  833. CodeDomProvider provider = new CSharpCodeProvider ();
  834. ICodeGenerator generator = provider.CreateGenerator ();
  835. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  836. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  837. "{0}{0}" +
  838. "/// <remarks/>{0}" +
  839. "[System.FlagsAttribute()]{0}" +
  840. #if NET_2_0
  841. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  842. "[System.SerializableAttribute()]{0}" +
  843. #endif
  844. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
  845. "public enum ZeroFlagEnum {{{0}" +
  846. " {0}" +
  847. " /// <remarks/>{0}" +
  848. " [System.Xml.Serialization.XmlEnumAttribute(\"zero\")]{0}" +
  849. " e0 = 1,{0}" +
  850. " {0}" +
  851. " /// <remarks/>{0}" +
  852. " [System.Xml.Serialization.XmlEnumAttribute(\"o<n>e\")]{0}" +
  853. " e1 = 2,{0}" +
  854. " {0}" +
  855. " /// <remarks/>{0}" +
  856. " [System.Xml.Serialization.XmlEnumAttribute(\"tns:t<w>o\")]{0}" +
  857. " e2 = 4,{0}" +
  858. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  859. }
  860. CodeNamespace ExportCode (Type type)
  861. {
  862. XmlReflectionImporter imp = new XmlReflectionImporter ();
  863. XmlTypeMapping map = imp.ImportTypeMapping (type);
  864. CodeNamespace codeNamespace = new CodeNamespace ();
  865. XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
  866. exp.ExportTypeMapping (map);
  867. return codeNamespace;
  868. }
  869. [XmlRootAttribute ("root", Namespace="urn:aNS", IsNullable=false)]
  870. public class Root
  871. {
  872. public OptionalValueTypeContainer OptionalValue;
  873. public TestDefault Default;
  874. }
  875. }
  876. }