2 // System.Xml.Serialization.XmlCodeExporterTests
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // (C) Gert Driesen (drieseng@users.sourceforge.net)
15 using System.CodeDom.Compiler;
16 using System.Collections;
17 using System.Globalization;
20 using System.Reflection;
23 using System.Xml.Schema;
24 using System.Xml.Serialization;
26 using Microsoft.CSharp;
28 using NUnit.Framework;
30 using MonoTests.System.Xml.TestClasses;
32 namespace MonoTests.System.XmlSerialization
35 public class XmlCodeExporterTests
38 public void ExportTypeMapping_ArrayClass ()
40 CodeNamespace codeNamespace = ExportCode (typeof (ArrayClass));
41 Assert.IsNotNull (codeNamespace, "#1");
43 StringWriter sw = new StringWriter ();
44 CodeDomProvider provider = new CSharpCodeProvider ();
45 ICodeGenerator generator = provider.CreateGenerator ();
46 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
48 Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
52 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
53 "[System.SerializableAttribute()]{0}" +
54 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
55 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
56 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
57 "public partial class ArrayClass {{{0}" +
59 " private object namesField;{0}" +
61 " /// <remarks/>{0}" +
62 " public object names {{{0}" +
64 " return this.namesField;{0}" +
67 " this.namesField = value;{0}" +
70 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
72 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
73 "public class ArrayClass {{{0}" +
75 " /// <remarks/>{0}" +
76 " public object names;{0}" +
77 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
81 codeNamespace = ExportCode (typeof (ArrayClass[]));
82 Assert.IsNotNull (codeNamespace, "#3");
84 sw.GetStringBuilder ().Length = 0;
85 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
87 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
91 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
92 "[System.SerializableAttribute()]{0}" +
93 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
94 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
95 "public partial class ArrayClass {{{0}" +
97 " private object namesField;{0}" +
99 " /// <remarks/>{0}" +
100 " public object names {{{0}" +
102 " return this.namesField;{0}" +
105 " this.namesField = value;{0}" +
108 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
110 "public class ArrayClass {{{0}" +
112 " /// <remarks/>{0}" +
113 " public object names;{0}" +
114 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
119 public void ExportTypeMapping_ArrayContainer ()
121 CodeNamespace codeNamespace = ExportCode (typeof (ArrayContainer));
122 Assert.IsNotNull (codeNamespace, "#1");
124 StringWriter sw = new StringWriter ();
125 CodeDomProvider provider = new CSharpCodeProvider ();
126 ICodeGenerator generator = provider.CreateGenerator ();
127 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
129 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
131 "/// <remarks/>{0}" +
133 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
134 "[System.SerializableAttribute()]{0}" +
135 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
136 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
137 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
138 "public partial class ArrayContainer {{{0}" +
140 " private object[] itemsField;{0}" +
142 " /// <remarks/>{0}" +
143 " public object[] items {{{0}" +
145 " return this.itemsField;{0}" +
148 " this.itemsField = value;{0}" +
151 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
153 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
154 "public class ArrayContainer {{{0}" +
156 " /// <remarks/>{0}" +
157 " public object[] items;{0}" +
158 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
163 public void ExportTypeMapping_CDataContainer ()
165 CodeNamespace codeNamespace = ExportCode (typeof (CDataContainer));
166 Assert.IsNotNull (codeNamespace, "#1");
168 StringWriter sw = new StringWriter ();
169 CodeDomProvider provider = new CSharpCodeProvider ();
170 ICodeGenerator generator = provider.CreateGenerator ();
171 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
173 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
175 "/// <remarks/>{0}" +
177 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
178 "[System.SerializableAttribute()]{0}" +
179 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
180 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
181 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
182 "public partial class CDataContainer {{{0}" +
184 " private System.Xml.XmlCDataSection cdataField;{0}" +
186 " /// <remarks/>{0}" +
187 " public System.Xml.XmlCDataSection cdata {{{0}" +
189 " return this.cdataField;{0}" +
192 " this.cdataField = value;{0}" +
195 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
197 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
198 "public class CDataContainer {{{0}" +
200 " /// <remarks/>{0}" +
201 " public System.Xml.XmlCDataSection cdata;{0}" +
202 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
207 [Category ("NotWorking")] // order of XmlElementAttribute's does not match that of MSFT
208 [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
209 public void ExportTypeMapping_Choices ()
211 CodeNamespace codeNamespace = ExportCode (typeof (Choices));
212 Assert.IsNotNull (codeNamespace, "#1");
214 StringWriter sw = new StringWriter ();
215 CodeDomProvider provider = new CSharpCodeProvider ();
216 ICodeGenerator generator = provider.CreateGenerator ();
217 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
219 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
221 "/// <remarks/>{0}" +
223 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
224 "[System.SerializableAttribute()]{0}" +
225 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
226 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
227 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
228 "public partial class Choices {{{0}" +
230 " private string myChoiceField;{0}" +
232 " /// <remarks/>{0}" +
233 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
234 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
235 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
236 " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
237 " public string MyChoice {{{0}" +
239 " return this.myChoiceField;{0}" +
242 " this.myChoiceField = value;{0}" +
245 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
247 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
248 "public class Choices {{{0}" +
250 " /// <remarks/>{0}" +
251 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
252 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
253 " [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
254 " [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
255 " public string MyChoice;{0}" +
256 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
261 [Category ("NotWorking")] // TODO: order of DefaultValueAttribute, ...
262 public void ExportTypeMapping_Field ()
264 CodeNamespace codeNamespace = ExportCode (typeof (Field));
265 Assert.IsNotNull (codeNamespace, "#1");
267 StringWriter sw = new StringWriter ();
268 CodeDomProvider provider = new CSharpCodeProvider ();
269 ICodeGenerator generator = provider.CreateGenerator ();
270 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
272 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
274 "/// <remarks/>{0}" +
276 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
277 "[System.SerializableAttribute()]{0}" +
278 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
279 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
280 "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
281 "public partial class Field {{{0}" +
283 " private MonoTests.System.Xml.TestClasses.FlagEnum flags1Field;{0}" +
285 " private MonoTests.System.Xml.TestClasses.FlagEnum flags2Field;{0}" +
287 " private MonoTests.System.Xml.TestClasses.FlagEnum flags3Field;{0}" +
289 " private MonoTests.System.Xml.TestClasses.FlagEnum flags4Field;{0}" +
291 " private MonoTests.System.Xml.TestClasses.MapModifiers modifiersField;{0}" +
293 " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers2Field;{0}" +
295 " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers3Field;{0}" +
297 " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers4Field;{0}" +
299 " private MonoTests.System.Xml.TestClasses.MapModifiers modifiers5Field;{0}" +
301 " private string[] namesField;{0}" +
303 " private string streetField;{0}" +
305 " public Field() {{{0}" +
306 " this.flags1Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
307 " this.flags2Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
308 " this.flags3Field = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
309 " this.modifiers3Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
310 " this.modifiers4Field = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
311 " this.modifiers5Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
314 " /// <remarks/>{0}" +
315 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
316 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 {{{0}" +
318 " return this.flags1Field;{0}" +
321 " this.flags1Field = value;{0}" +
325 " /// <remarks/>{0}" +
326 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
327 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 {{{0}" +
329 " return this.flags2Field;{0}" +
332 " this.flags2Field = value;{0}" +
336 " /// <remarks/>{0}" +
337 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
338 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 {{{0}" +
340 " return this.flags3Field;{0}" +
343 " this.flags3Field = value;{0}" +
347 " /// <remarks/>{0}" +
348 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
349 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags4 {{{0}" +
351 " return this.flags4Field;{0}" +
354 " this.flags4Field = value;{0}" +
358 " /// <remarks/>{0}" +
359 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
360 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers {{{0}" +
362 " return this.modifiersField;{0}" +
365 " this.modifiersField = value;{0}" +
369 " /// <remarks/>{0}" +
370 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
371 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2 {{{0}" +
373 " return this.modifiers2Field;{0}" +
376 " this.modifiers2Field = value;{0}" +
380 " /// <remarks/>{0}" +
381 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
382 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 {{{0}" +
384 " return this.modifiers3Field;{0}" +
387 " this.modifiers3Field = value;{0}" +
391 " /// <remarks/>{0}" +
392 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
393 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 {{{0}" +
395 " return this.modifiers4Field;{0}" +
398 " this.modifiers4Field = value;{0}" +
402 " /// <remarks/>{0}" +
403 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
404 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 {{{0}" +
406 " return this.modifiers5Field;{0}" +
409 " this.modifiers5Field = value;{0}" +
413 " /// <remarks/>{0}" +
414 " [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
415 " public string[] Names {{{0}" +
417 " return this.namesField;{0}" +
420 " this.namesField = value;{0}" +
424 " /// <remarks/>{0}" +
425 " [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
426 " public string Street {{{0}" +
428 " return this.streetField;{0}" +
431 " this.streetField = value;{0}" +
435 "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
436 "public class Field {{{0}" +
438 " /// <remarks/>{0}" +
439 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
440 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
441 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
443 " /// <remarks/>{0}" +
444 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
445 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
446 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
448 " /// <remarks/>{0}" +
449 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
450 " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
451 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
453 " /// <remarks/>{0}" +
454 " [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
455 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags4;{0}" +
457 " /// <remarks/>{0}" +
458 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
459 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers;{0}" +
461 " /// <remarks/>{0}" +
462 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
463 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2;{0}" +
465 " /// <remarks/>{0}" +
466 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
467 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
468 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
470 " /// <remarks/>{0}" +
471 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
472 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
473 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
475 " /// <remarks/>{0}" +
476 " [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
477 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
478 " public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
480 " /// <remarks/>{0}" +
481 " [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
482 " public string[] Names;{0}" +
484 " /// <remarks/>{0}" +
485 " [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
486 " public string Street;{0}" +
490 "/// <remarks/>{0}" +
491 "[System.FlagsAttribute()]{0}" +
493 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
494 "[System.SerializableAttribute()]{0}" +
496 "public enum FlagEnum {{{0}" +
498 " /// <remarks/>{0}" +
499 " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
502 " /// <remarks/>{0}" +
503 " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
506 " /// <remarks/>{0}" +
507 " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
511 "/// <remarks/>{0}" +
512 "[System.FlagsAttribute()]{0}" +
514 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
515 "[System.SerializableAttribute()]{0}" +
517 "public enum MapModifiers {{{0}" +
519 " /// <remarks/>{0}" +
520 " [System.Xml.Serialization.XmlEnumAttribute(\"public\")]{0}" +
523 " /// <remarks/>{0}" +
524 " [System.Xml.Serialization.XmlEnumAttribute(\"protected\")]{0}" +
525 " Protected = 2,{0}" +
527 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
529 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
534 public void ExportTypeMapping_ItemChoiceType ()
536 CodeNamespace codeNamespace = ExportCode (typeof (ItemChoiceType));
537 Assert.IsNotNull (codeNamespace, "#1");
539 StringWriter sw = new StringWriter ();
540 CodeDomProvider provider = new CSharpCodeProvider ();
541 ICodeGenerator generator = provider.CreateGenerator ();
542 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
544 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
546 "/// <remarks/>{0}" +
548 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
549 "[System.SerializableAttribute()]{0}" +
551 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
552 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
553 "public enum ItemChoiceType {{{0}" +
555 " /// <remarks/>{0}" +
558 " /// <remarks/>{0}" +
559 " [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
562 " /// <remarks/>{0}" +
565 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
567 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
570 codeNamespace = ExportCode (typeof (ItemChoiceType[]));
571 Assert.IsNotNull (codeNamespace, "#3");
573 sw.GetStringBuilder ().Length = 0;
574 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
576 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
578 "/// <remarks/>{0}" +
580 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
581 "[System.SerializableAttribute()]{0}" +
583 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
584 "public enum ItemChoiceType {{{0}" +
586 " /// <remarks/>{0}" +
589 " /// <remarks/>{0}" +
590 " [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
593 " /// <remarks/>{0}" +
596 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
598 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
603 public void ExportTypeMapping_ClassArrayContainer ()
605 CodeNamespace codeNamespace = ExportCode (typeof (ClassArrayContainer));
606 Assert.IsNotNull (codeNamespace, "#1");
608 StringWriter sw = new StringWriter ();
609 CodeDomProvider provider = new CSharpCodeProvider ();
610 ICodeGenerator generator = provider.CreateGenerator ();
611 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
613 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
615 "/// <remarks/>{0}" +
617 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
618 "[System.SerializableAttribute()]{0}" +
619 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
620 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
621 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
622 "public partial class ClassArrayContainer {{{0}" +
624 " private MonoTests.System.Xml.TestClasses.SimpleClass[] itemsField;{0}" +
626 " /// <remarks/>{0}" +
627 " public MonoTests.System.Xml.TestClasses.SimpleClass[] items {{{0}" +
629 " return this.itemsField;{0}" +
632 " this.itemsField = value;{0}" +
637 "/// <remarks/>{0}" +
638 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
639 "[System.SerializableAttribute()]{0}" +
640 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
641 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
642 "public partial class SimpleClass {{{0}" +
644 " private string somethingField;{0}" +
646 " /// <remarks/>{0}" +
647 " public string something {{{0}" +
649 " return this.somethingField;{0}" +
652 " this.somethingField = value;{0}" +
655 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
657 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
658 "public class ClassArrayContainer {{{0}" +
660 " /// <remarks/>{0}" +
661 " public MonoTests.System.Xml.TestClasses.SimpleClass[] items;{0}" +
664 "/// <remarks/>{0}" +
665 "public class SimpleClass {{{0}" +
667 " /// <remarks/>{0}" +
668 " public string something;{0}" +
669 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
674 [Category ("NotWorking")] // bug #78214
675 public void ExportTypeMapping_Root ()
677 CodeNamespace codeNamespace = ExportCode (typeof (Root));
678 Assert.IsNotNull (codeNamespace, "#1");
680 StringWriter sw = new StringWriter ();
681 CodeDomProvider provider = new CSharpCodeProvider ();
682 ICodeGenerator generator = provider.CreateGenerator ();
683 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
685 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
687 "/// <remarks/>{0}" +
689 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
690 "[System.SerializableAttribute()]{0}" +
691 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
692 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
693 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
694 "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
695 "public partial class Root {{{0}" +
697 " private MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer optionalValueField;{0}" +
699 " private MonoTests.System.Xml.TestClasses.TestDefault defaultField;{0}" +
701 " /// <remarks/>{0}" +
702 " public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue {{{0}" +
704 " return this.optionalValueField;{0}" +
707 " this.optionalValueField = value;{0}" +
711 " /// <remarks/>{0}" +
712 " public MonoTests.System.Xml.TestClasses.TestDefault Default {{{0}" +
714 " return this.defaultField;{0}" +
717 " this.defaultField = value;{0}" +
722 "/// <remarks/>{0}" +
723 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
724 "[System.SerializableAttribute()]{0}" +
725 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
726 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
727 "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
728 "public partial class OptionalValueTypeContainer {{{0}" +
730 " private MonoTests.System.Xml.TestClasses.FlagEnum attributesField;{0}" +
732 " private MonoTests.System.Xml.TestClasses.FlagEnum flagsField;{0}" +
734 " private bool flagsFieldSpecified;{0}" +
736 " private bool isEmptyField;{0}" +
738 " private bool isEmptyFieldSpecified;{0}" +
740 " private bool isNullField;{0}" +
742 " public OptionalValueTypeContainer() {{{0}" +
743 " this.attributesField = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
744 " this.flagsField = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
747 " /// <remarks/>{0}" +
748 " public MonoTests.System.Xml.TestClasses.FlagEnum Attributes {{{0}" +
750 " return this.attributesField;{0}" +
753 " this.attributesField = value;{0}" +
757 " /// <remarks/>{0}" +
758 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags {{{0}" +
760 " return this.flagsField;{0}" +
763 " this.flagsField = value;{0}" +
767 " /// <remarks/>{0}" +
768 " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
769 " public bool FlagsSpecified {{{0}" +
771 " return this.flagsFieldSpecified;{0}" +
774 " this.flagsFieldSpecified = value;{0}" +
778 " /// <remarks/>{0}" +
779 " public bool IsEmpty {{{0}" +
781 " return this.isEmptyField;{0}" +
784 " this.isEmptyField = value;{0}" +
788 " /// <remarks/>{0}" +
789 " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
790 " public bool IsEmptySpecified {{{0}" +
792 " return this.isEmptyFieldSpecified;{0}" +
795 " this.isEmptyFieldSpecified = value;{0}" +
799 " /// <remarks/>{0}" +
800 " public bool IsNull {{{0}" +
802 " return this.isNullField;{0}" +
805 " this.isNullField = value;{0}" +
810 "/// <remarks/>{0}" +
811 "[System.FlagsAttribute()]{0}" +
812 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
813 "[System.SerializableAttribute()]{0}" +
814 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
815 "public enum FlagEnum {{{0}" +
817 " /// <remarks/>{0}" +
818 " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
821 " /// <remarks/>{0}" +
822 " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
825 " /// <remarks/>{0}" +
826 " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
830 "/// <remarks/>{0}" +
831 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
832 "[System.SerializableAttribute()]{0}" +
833 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
834 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
835 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
836 "public partial class TestDefault {{{0}" +
838 " private string strField;{0}" +
840 " private string strDefaultField;{0}" +
842 " private bool boolTField;{0}" +
844 " private bool boolFField;{0}" +
846 " private decimal decimalvalField;{0}" +
848 " private MonoTests.System.Xml.TestClasses.FlagEnum flagField;{0}" +
850 " private MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencodedField;{0}" +
852 " public TestDefault() {{{0}" +
853 " this.strDefaultField = \"Default Value\";{0}" +
854 " this.flagField = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
855 " this.flagencodedField = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
858 " /// <remarks/>{0}" +
859 " public string str {{{0}" +
861 " return this.strField;{0}" +
864 " this.strField = value;{0}" +
868 " /// <remarks/>{0}" +
869 " public string strDefault {{{0}" +
871 " return this.strDefaultField;{0}" +
874 " this.strDefaultField = value;{0}" +
878 " /// <remarks/>{0}" +
879 " public bool boolT {{{0}" +
881 " return this.boolTField;{0}" +
884 " this.boolTField = value;{0}" +
888 " /// <remarks/>{0}" +
889 " public bool boolF {{{0}" +
891 " return this.boolFField;{0}" +
894 " this.boolFField = value;{0}" +
898 " /// <remarks/>{0}" +
899 " public decimal decimalval {{{0}" +
901 " return this.decimalvalField;{0}" +
904 " this.decimalvalField = value;{0}" +
908 " /// <remarks/>{0}" +
909 " public MonoTests.System.Xml.TestClasses.FlagEnum flag {{{0}" +
911 " return this.flagField;{0}" +
914 " this.flagField = value;{0}" +
918 " /// <remarks/>{0}" +
919 " public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded {{{0}" +
921 " return this.flagencodedField;{0}" +
924 " this.flagencodedField = value;{0}" +
929 "/// <remarks/>{0}" +
930 "[System.FlagsAttribute()]{0}" +
931 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
932 "[System.SerializableAttribute()]{0}" +
933 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
934 "public enum FlagEnum {{{0}" +
936 " /// <remarks/>{0}" +
937 " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
940 " /// <remarks/>{0}" +
941 " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
944 " /// <remarks/>{0}" +
945 " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
949 "/// <remarks/>{0}" +
950 "[System.FlagsAttribute()]{0}" +
951 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
952 "[System.SerializableAttribute()]{0}" +
953 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
954 "public enum FlagEnum_Encoded {{{0}" +
956 " /// <remarks/>{0}" +
959 " /// <remarks/>{0}" +
962 " /// <remarks/>{0}" +
964 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
966 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
967 "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
968 "public class Root {{{0}" +
970 " /// <remarks/>{0}" +
971 " public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue;{0}" +
973 " /// <remarks/>{0}" +
974 " public MonoTests.System.Xml.TestClasses.TestDefault Default;{0}" +
977 "/// <remarks/>{0}" +
978 "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
979 "public class OptionalValueTypeContainer {{{0}" +
981 " /// <remarks/>{0}" +
982 " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
983 " public MonoTests.System.Xml.TestClasses.FlagEnum Attributes = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
985 " /// <remarks/>{0}" +
986 " [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
987 " public MonoTests.System.Xml.TestClasses.FlagEnum Flags = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
989 " /// <remarks/>{0}" +
990 " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
991 " public bool FlagsSpecified;{0}" +
993 " /// <remarks/>{0}" +
994 " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
995 " public bool IsEmpty = false;{0}" +
997 " /// <remarks/>{0}" +
998 " [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
999 " public bool IsEmptySpecified;{0}" +
1001 " /// <remarks/>{0}" +
1002 " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
1003 " public bool IsNull = false;{0}" +
1006 "/// <remarks/>{0}" +
1007 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
1008 "[System.FlagsAttribute()]{0}" +
1009 "public enum FlagEnum {{{0}" +
1011 " /// <remarks/>{0}" +
1012 " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
1015 " /// <remarks/>{0}" +
1016 " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
1019 " /// <remarks/>{0}" +
1020 " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
1024 "/// <remarks/>{0}" +
1025 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1026 "public class TestDefault {{{0}" +
1028 " /// <remarks/>{0}" +
1029 " public string str;{0}" +
1031 " /// <remarks/>{0}" +
1032 " [System.ComponentModel.DefaultValueAttribute(\"Default Value\")]{0}" +
1033 " public string strDefault = \"Default Value\";{0}" +
1035 " /// <remarks/>{0}" +
1036 " [System.ComponentModel.DefaultValueAttribute(true)]{0}" +
1037 " public bool boolT = true;{0}" +
1039 " /// <remarks/>{0}" +
1040 " [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
1041 " public bool boolF = false;{0}" +
1043 " /// <remarks/>{0}" +
1044 " [System.ComponentModel.DefaultValueAttribute(typeof(System.Decimal), \"10\")]{0}" +
1045 " public System.Decimal decimalval = ((System.Decimal)(10m));{0}" +
1047 " /// <remarks/>{0}" +
1048 " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
1049 " public MonoTests.System.Xml.TestClasses.FlagEnum flag = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
1051 " /// <remarks/>{0}" +
1052 " [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4))]{0}" +
1053 " public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
1056 "/// <remarks/>{0}" +
1057 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1058 "[System.FlagsAttribute()]{0}" +
1059 "public enum FlagEnum {{{0}" +
1061 " /// <remarks/>{0}" +
1062 " [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
1065 " /// <remarks/>{0}" +
1066 " [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
1069 " /// <remarks/>{0}" +
1070 " [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
1074 "/// <remarks/>{0}" +
1075 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1076 "[System.FlagsAttribute()]{0}" +
1077 "public enum FlagEnum_Encoded {{{0}" +
1079 " /// <remarks/>{0}" +
1082 " /// <remarks/>{0}" +
1085 " /// <remarks/>{0}" +
1087 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1092 public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
1094 CodeNamespace codeNamespace = ExportCode (typeof (SimpleClassWithXmlAttributes));
1095 Assert.IsNotNull (codeNamespace, "#1");
1097 StringWriter sw = new StringWriter ();
1098 CodeDomProvider provider = new CSharpCodeProvider ();
1099 ICodeGenerator generator = provider.CreateGenerator ();
1100 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1102 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1104 "/// <remarks/>{0}" +
1106 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
1107 "[System.SerializableAttribute()]{0}" +
1108 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
1109 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
1110 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
1111 "public partial class SimpleClassWithXmlAttributes {{{0}" +
1113 " private string somethingField;{0}" +
1115 " /// <remarks/>{0}" +
1116 " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
1117 " public string something {{{0}" +
1119 " return this.somethingField;{0}" +
1122 " this.somethingField = value;{0}" +
1125 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
1127 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
1128 "public class SimpleClassWithXmlAttributes {{{0}" +
1130 " /// <remarks/>{0}" +
1131 " [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
1132 " public string something;{0}" +
1133 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1138 public void ExportTypeMapping_XsdPrimitive_Arrays ()
1140 ArrayList types = new ArrayList ();
1141 types.Add (typeof (sbyte[]));
1142 types.Add (typeof (bool[]));
1143 types.Add (typeof (short[]));
1144 types.Add (typeof (int[]));
1145 types.Add (typeof (long[]));
1146 types.Add (typeof (float[]));
1147 types.Add (typeof (double[]));
1148 types.Add (typeof (decimal[]));
1149 types.Add (typeof (ushort[]));
1150 types.Add (typeof (uint[]));
1151 types.Add (typeof (ulong[]));
1152 types.Add (typeof (DateTime[]));
1153 types.Add (typeof (XmlQualifiedName[]));
1154 types.Add (typeof (string[]));
1156 StringWriter sw = new StringWriter ();
1157 CodeDomProvider provider = new CSharpCodeProvider ();
1158 ICodeGenerator generator = provider.CreateGenerator ();
1160 foreach (Type type in types) {
1161 CodeNamespace codeNamespace = ExportCode (type);
1162 Assert.IsNotNull (codeNamespace, type.FullName + "#1");
1164 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1166 Assert.AreEqual (Environment.NewLine, sw.ToString (),
1167 type.FullName + "#2");
1169 sw.GetStringBuilder ().Length = 0;
1174 public void ExportTypeMapping_ZeroFlagEnum ()
1176 CodeNamespace codeNamespace = ExportCode (typeof (ZeroFlagEnum));
1177 Assert.IsNotNull (codeNamespace, "#1");
1179 StringWriter sw = new StringWriter ();
1180 CodeDomProvider provider = new CSharpCodeProvider ();
1181 ICodeGenerator generator = provider.CreateGenerator ();
1182 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1184 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1186 "/// <remarks/>{0}" +
1187 "[System.FlagsAttribute()]{0}" +
1189 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
1190 "[System.SerializableAttribute()]{0}" +
1192 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
1193 "public enum ZeroFlagEnum {{{0}" +
1195 " /// <remarks/>{0}" +
1196 " [System.Xml.Serialization.XmlEnumAttribute(\"zero\")]{0}" +
1199 " /// <remarks/>{0}" +
1200 " [System.Xml.Serialization.XmlEnumAttribute(\"o<n>e\")]{0}" +
1203 " /// <remarks/>{0}" +
1204 " [System.Xml.Serialization.XmlEnumAttribute(\"tns:t<w>o\")]{0}" +
1207 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
1209 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1214 public void DuplicateIdentifiers ()
1216 XmlSchema xs = XmlSchema.Read (File.OpenText ("Test/XmlFiles/xsd/82078.xsd"), null);
1218 XmlSchemas xss = new XmlSchemas ();
1220 XmlSchemaImporter imp = new XmlSchemaImporter (xss);
1221 CodeNamespace cns = new CodeNamespace ();
1222 XmlCodeExporter exp = new XmlCodeExporter (cns);
1223 XmlQualifiedName qname = new XmlQualifiedName (
1224 "Operation", "http://tempuri.org/");
1225 exp.ExportTypeMapping (imp.ImportTypeMapping (qname));
1226 CodeCompileUnit ccu = new CodeCompileUnit ();
1227 ccu.Namespaces.Add (cns);
1229 CodeDomProvider provider = new CSharpCodeProvider ();
1230 ICodeCompiler compiler = provider.CreateCompiler ();
1232 CompilerParameters options = new CompilerParameters ();
1233 options.ReferencedAssemblies.Add ("System.dll");
1234 options.ReferencedAssemblies.Add ("System.Xml.dll");
1235 options.GenerateInMemory = true;
1237 CompilerResults result = compiler.CompileAssemblyFromDom (options, ccu);
1238 Assert.AreEqual (0, result.Errors.Count, "#1");
1239 Assert.IsNotNull (result.CompiledAssembly, "#2");
1243 public void ExportSimpleContentExtensionEnum ()
1246 <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:b='urn:bar' targetNamespace='urn:bar'>
1247 <xs:element name='Foo' type='b:DayOfWeek' />
1248 <xs:complexType name='DayOfWeek'>
1250 <xs:extension base='b:WeekDay' />
1253 <xs:simpleType name='WeekDay'>
1254 <xs:restriction base='xs:string'>
1255 <xs:enumeration value='Sunday'/>
1256 <xs:enumeration value='Monday'/>
1257 <xs:enumeration value='Tuesday'/>
1258 <xs:enumeration value='Wednesday'/>
1259 <xs:enumeration value='Thursday'/>
1260 <xs:enumeration value='Friday'/>
1261 <xs:enumeration value='Saturday'/>
1265 XmlSchema xs = XmlSchema.Read (new StringReader (xsd), null);
1266 XmlSchemas xss = new XmlSchemas ();
1268 XmlSchemaImporter imp = new XmlSchemaImporter (xss);
1269 XmlTypeMapping m = imp.ImportTypeMapping (new XmlQualifiedName ("Foo", "urn:bar"));
1270 CodeNamespace cns = new CodeNamespace ();
1271 XmlCodeExporter exp = new XmlCodeExporter (cns);
1272 exp.ExportTypeMapping (m);
1273 CodeTypeDeclaration enumType = null;
1274 foreach (CodeTypeDeclaration ctd in cns.Types)
1275 if (ctd.Name == "WeekDay")
1277 Assert.IsNotNull (enumType);
1280 CodeNamespace ExportCode (Type type)
1282 XmlReflectionImporter imp = new XmlReflectionImporter ();
1283 XmlTypeMapping map = imp.ImportTypeMapping (type);
1284 CodeNamespace codeNamespace = new CodeNamespace ();
1285 XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
1286 exp.ExportTypeMapping (map);
1287 return codeNamespace;
1291 string XmlFileVersion {
1293 Assembly xmlAsm = typeof (XmlDocument).Assembly;
1294 AssemblyFileVersionAttribute afv = (AssemblyFileVersionAttribute)
1295 Attribute.GetCustomAttribute (xmlAsm, typeof (AssemblyFileVersionAttribute));
1301 [XmlRootAttribute ("root", Namespace="urn:aNS", IsNullable=false)]
1304 public OptionalValueTypeContainer OptionalValue;
1305 public TestDefault Default;