XmlCodeExporterTests.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. }
  66. [Test]
  67. public void ExportTypeMapping_ArrayContainer ()
  68. {
  69. CodeNamespace codeNamespace = ExportCode (typeof (ArrayContainer));
  70. Assert.IsNotNull (codeNamespace, "#1");
  71. StringWriter sw = new StringWriter ();
  72. CodeDomProvider provider = new CSharpCodeProvider ();
  73. ICodeGenerator generator = provider.CreateGenerator ();
  74. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  75. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  76. "{0}{0}" +
  77. "/// <remarks/>{0}" +
  78. #if NET_2_0
  79. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  80. "[System.SerializableAttribute()]{0}" +
  81. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  82. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  83. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  84. "public partial class ArrayContainer {{{0}" +
  85. " {0}" +
  86. " private object[] itemsField;{0}" +
  87. " {0}" +
  88. " /// <remarks/>{0}" +
  89. " public object[] items {{{0}" +
  90. " get {{{0}" +
  91. " return this.itemsField;{0}" +
  92. " }}{0}" +
  93. " set {{{0}" +
  94. " this.itemsField = value;{0}" +
  95. " }}{0}" +
  96. " }}{0}" +
  97. #else
  98. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  99. "public class ArrayContainer {{{0}" +
  100. " {0}" +
  101. " /// <remarks/>{0}" +
  102. " public object[] items;{0}" +
  103. #endif
  104. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  105. }
  106. [Test]
  107. public void ExportTypeMapping_CDataContainer ()
  108. {
  109. CodeNamespace codeNamespace = ExportCode (typeof (CDataContainer));
  110. Assert.IsNotNull (codeNamespace, "#1");
  111. StringWriter sw = new StringWriter ();
  112. CodeDomProvider provider = new CSharpCodeProvider ();
  113. ICodeGenerator generator = provider.CreateGenerator ();
  114. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  115. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  116. "{0}{0}" +
  117. "/// <remarks/>{0}" +
  118. #if NET_2_0
  119. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  120. "[System.SerializableAttribute()]{0}" +
  121. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  122. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  123. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  124. "public partial class CDataContainer {{{0}" +
  125. " {0}" +
  126. " private System.Xml.XmlCDataSection cdataField;{0}" +
  127. " {0}" +
  128. " /// <remarks/>{0}" +
  129. " public System.Xml.XmlCDataSection cdata {{{0}" +
  130. " get {{{0}" +
  131. " return this.cdataField;{0}" +
  132. " }}{0}" +
  133. " set {{{0}" +
  134. " this.cdataField = value;{0}" +
  135. " }}{0}" +
  136. " }}{0}" +
  137. #else
  138. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  139. "public class CDataContainer {{{0}" +
  140. " {0}" +
  141. " /// <remarks/>{0}" +
  142. " public System.Xml.XmlCDataSection cdata;{0}" +
  143. #endif
  144. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  145. }
  146. [Test]
  147. [Category ("NotWorking")] // order of XmlElementAttribute's does not match that of MSFT
  148. [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
  149. public void ExportTypeMapping_Choices ()
  150. {
  151. CodeNamespace codeNamespace = ExportCode (typeof (Choices));
  152. Assert.IsNotNull (codeNamespace, "#1");
  153. StringWriter sw = new StringWriter ();
  154. CodeDomProvider provider = new CSharpCodeProvider ();
  155. ICodeGenerator generator = provider.CreateGenerator ();
  156. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  157. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  158. "{0}{0}" +
  159. "/// <remarks/>{0}" +
  160. #if NET_2_0
  161. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  162. "[System.SerializableAttribute()]{0}" +
  163. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  164. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  165. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  166. "public partial class Choices {{{0}" +
  167. " {0}" +
  168. " private string myChoiceField;{0}" +
  169. " {0}" +
  170. " /// <remarks/>{0}" +
  171. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
  172. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
  173. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
  174. " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
  175. " public string MyChoice {{{0}" +
  176. " get {{{0}" +
  177. " return this.myChoiceField;{0}" +
  178. " }}{0}" +
  179. " set {{{0}" +
  180. " this.myChoiceField = value;{0}" +
  181. " }}{0}" +
  182. " }}{0}" +
  183. #else
  184. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  185. "public class Choices {{{0}" +
  186. " {0}" +
  187. " /// <remarks/>{0}" +
  188. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
  189. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
  190. " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
  191. " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
  192. " public string MyChoice;{0}" +
  193. #endif
  194. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  195. }
  196. [Test]
  197. #if NET_2_0
  198. [Category ("NotDotNet")] // regression in MS.NET 2.0
  199. #endif
  200. [Category ("NotWorking")] // TODO: order of DefaultValueAttribute, ...
  201. public void ExportTypeMapping_Field ()
  202. {
  203. CodeNamespace codeNamespace = ExportCode (typeof (Field));
  204. Assert.IsNotNull (codeNamespace, "#1");
  205. StringWriter sw = new StringWriter ();
  206. CodeDomProvider provider = new CSharpCodeProvider ();
  207. ICodeGenerator generator = provider.CreateGenerator ();
  208. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  209. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  210. "{0}{0}" +
  211. "/// <remarks/>{0}" +
  212. "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
  213. "public class Field {{{0}" +
  214. " {0}" +
  215. " /// <remarks/>{0}" +
  216. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
  217. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers;{0}" +
  218. " {0}" +
  219. " /// <remarks/>{0}" +
  220. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
  221. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2;{0}" +
  222. " {0}" +
  223. " /// <remarks/>{0}" +
  224. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
  225. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  226. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  227. " {0}" +
  228. " /// <remarks/>{0}" +
  229. " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
  230. " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
  231. " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
  232. " {0}" +
  233. " /// <remarks/>{0}" +
  234. " [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
  235. " public string[] Names;{0}" +
  236. " {0}" +
  237. " /// <remarks/>{0}" +
  238. " [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
  239. " public string Street;{0}" +
  240. "}}{0}" +
  241. "{0}" +
  242. "/// <remarks/>{0}" +
  243. "[System.FlagsAttribute()]{0}" +
  244. "public enum MapModifiers {{{0}" +
  245. " {0}" +
  246. " /// <remarks/>{0}" +
  247. " [System.Xml.Serialization.XmlEnumAttribute(\"public\")]{0}" +
  248. " Public = 1,{0}" +
  249. " {0}" +
  250. " /// <remarks/>{0}" +
  251. " [System.Xml.Serialization.XmlEnumAttribute(\"protected\")]{0}" +
  252. " Protected = 2,{0}" +
  253. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  254. }
  255. [Test]
  256. public void ExportTypeMapping_ItemChoiceType ()
  257. {
  258. CodeNamespace codeNamespace = ExportCode (typeof (ItemChoiceType));
  259. Assert.IsNotNull (codeNamespace, "#1");
  260. StringWriter sw = new StringWriter ();
  261. CodeDomProvider provider = new CSharpCodeProvider ();
  262. ICodeGenerator generator = provider.CreateGenerator ();
  263. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  264. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  265. "{0}{0}" +
  266. "/// <remarks/>{0}" +
  267. #if NET_2_0
  268. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  269. "[System.SerializableAttribute()]{0}" +
  270. #endif
  271. "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
  272. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
  273. "public enum ItemChoiceType {{{0}" +
  274. " {0}" +
  275. " /// <remarks/>{0}" +
  276. " ChoiceZero,{0}" +
  277. " {0}" +
  278. " /// <remarks/>{0}" +
  279. " [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
  280. " StrangeOne,{0}" +
  281. " {0}" +
  282. " /// <remarks/>{0}" +
  283. " ChoiceTwo,{0}" +
  284. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  285. }
  286. [Test]
  287. [Category ("NotWorking")] // Mono outputs XmlRootAttribute for SimpleClass too
  288. public void ExportTypeMapping_ClassArrayContainer ()
  289. {
  290. CodeNamespace codeNamespace = ExportCode (typeof (ClassArrayContainer));
  291. Assert.IsNotNull (codeNamespace, "#1");
  292. StringWriter sw = new StringWriter ();
  293. CodeDomProvider provider = new CSharpCodeProvider ();
  294. ICodeGenerator generator = provider.CreateGenerator ();
  295. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  296. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  297. "{0}{0}" +
  298. "/// <remarks/>{0}" +
  299. #if NET_2_0
  300. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  301. "[System.SerializableAttribute()]{0}" +
  302. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  303. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  304. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  305. "public partial class ClassArrayContainer {{{0}" +
  306. " {0}" +
  307. " private MonoTests.System.Xml.TestClasses.SimpleClass[] itemsField;{0}" +
  308. " {0}" +
  309. " /// <remarks/>{0}" +
  310. " public MonoTests.System.Xml.TestClasses.SimpleClass[] items {{{0}" +
  311. " get {{{0}" +
  312. " return this.itemsField;{0}" +
  313. " }}{0}" +
  314. " set {{{0}" +
  315. " this.itemsField = value;{0}" +
  316. " }}{0}" +
  317. " }}{0}" +
  318. "}}{0}" +
  319. "{0}" +
  320. "/// <remarks/>{0}" +
  321. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  322. "[System.SerializableAttribute()]{0}" +
  323. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  324. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  325. "public partial class SimpleClass {{{0}" +
  326. " {0}" +
  327. " private string somethingField;{0}" +
  328. " {0}" +
  329. " /// <remarks/>{0}" +
  330. " public string something {{{0}" +
  331. " get {{{0}" +
  332. " return this.somethingField;{0}" +
  333. " }}{0}" +
  334. " set {{{0}" +
  335. " this.somethingField = value;{0}" +
  336. " }}{0}" +
  337. " }}{0}" +
  338. #else
  339. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
  340. "public class ClassArrayContainer {{{0}" +
  341. " {0}" +
  342. " /// <remarks/>{0}" +
  343. " public MonoTests.System.Xml.TestClasses.SimpleClass[] items;{0}" +
  344. "}}{0}" +
  345. "{0}" +
  346. "/// <remarks/>{0}" +
  347. "public class SimpleClass {{{0}" +
  348. " {0}" +
  349. " /// <remarks/>{0}" +
  350. " public string something;{0}" +
  351. #endif
  352. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  353. }
  354. [Test]
  355. public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
  356. {
  357. CodeNamespace codeNamespace = ExportCode (typeof (SimpleClassWithXmlAttributes));
  358. Assert.IsNotNull (codeNamespace, "#1");
  359. StringWriter sw = new StringWriter ();
  360. CodeDomProvider provider = new CSharpCodeProvider ();
  361. ICodeGenerator generator = provider.CreateGenerator ();
  362. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  363. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  364. "{0}{0}" +
  365. "/// <remarks/>{0}" +
  366. #if NET_2_0
  367. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  368. "[System.SerializableAttribute()]{0}" +
  369. "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
  370. "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
  371. "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
  372. "public partial class SimpleClassWithXmlAttributes {{{0}" +
  373. " {0}" +
  374. " private string somethingField;{0}" +
  375. " {0}" +
  376. " /// <remarks/>{0}" +
  377. " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
  378. " public string something {{{0}" +
  379. " get {{{0}" +
  380. " return this.somethingField;{0}" +
  381. " }}{0}" +
  382. " set {{{0}" +
  383. " this.somethingField = value;{0}" +
  384. " }}{0}" +
  385. " }}{0}" +
  386. #else
  387. "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
  388. "public class SimpleClassWithXmlAttributes {{{0}" +
  389. " {0}" +
  390. " /// <remarks/>{0}" +
  391. " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
  392. " public string something;{0}" +
  393. #endif
  394. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  395. }
  396. [Test]
  397. public void ExportTypeMapping_ZeroFlagEnum ()
  398. {
  399. CodeNamespace codeNamespace = ExportCode (typeof (ZeroFlagEnum));
  400. Assert.IsNotNull (codeNamespace, "#1");
  401. StringWriter sw = new StringWriter ();
  402. CodeDomProvider provider = new CSharpCodeProvider ();
  403. ICodeGenerator generator = provider.CreateGenerator ();
  404. generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
  405. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  406. "{0}{0}" +
  407. "/// <remarks/>{0}" +
  408. "[System.FlagsAttribute()]{0}" +
  409. #if NET_2_0
  410. "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"2.0.50727.42\")]{0}" +
  411. "[System.SerializableAttribute()]{0}" +
  412. #endif
  413. "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
  414. "public enum ZeroFlagEnum {{{0}" +
  415. " {0}" +
  416. " /// <remarks/>{0}" +
  417. " [System.Xml.Serialization.XmlEnumAttribute(\"zero\")]{0}" +
  418. " e0 = 1,{0}" +
  419. " {0}" +
  420. " /// <remarks/>{0}" +
  421. " [System.Xml.Serialization.XmlEnumAttribute(\"o<n>e\")]{0}" +
  422. " e1 = 2,{0}" +
  423. " {0}" +
  424. " /// <remarks/>{0}" +
  425. " [System.Xml.Serialization.XmlEnumAttribute(\"tns:t<w>o\")]{0}" +
  426. " e2 = 4,{0}" +
  427. "}}{0}", Environment.NewLine), sw.ToString (), "#2");
  428. }
  429. CodeNamespace ExportCode (Type type)
  430. {
  431. XmlReflectionImporter imp = new XmlReflectionImporter ();
  432. XmlTypeMapping map = imp.ImportTypeMapping (type);
  433. CodeNamespace codeNamespace = new CodeNamespace ();
  434. XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
  435. exp.ExportTypeMapping (map);
  436. return codeNamespace;
  437. }
  438. }
  439. }