Author: gert
Date: 2006-05-15 11:53:35 -0400 (Mon, 15 May 2006)
New Revision: 60710
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlCodeExporterTests.cs
Log:
* XmlCodeExporterTests.cs: Added tests for arrays. Fixed usage of
XmlRootAttribute in tests.
* XmlCodeExporter.cs: Added bool argument to GenerateClass and
GenerateEnum methods that specifies whether we're dealing with a type
for a top-level element. In GenerateClass, do not always add Namespace
argument for XmlRootAttribute if isTopLevel is false, and do not
emit XmlRootAttribute if isTopLevel is false and no arguments have been
added.
* SoapCodeExporter.cs: Added bool argument to GenerateClass and
GenerateEnum methods.
* MapCodeGenerator.cs: Added bool argument to GenerateClass and
GenerateEnum methods.
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2006-05-15 15:05:21 UTC (rev 60709)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2006-05-15 15:53:35 UTC (rev 60710)
@@ -1,3 +1,16 @@
+2006-05-15 Gert Driesen <[EMAIL PROTECTED]>
+
+ * XmlCodeExporter.cs: Added bool argument to GenerateClass and
+ GenerateEnum methods that specifies whether we're dealing with a type
+ for a top-level element. In GenerateClass, do not always add Namespace
+ argument for XmlRootAttribute if isTopLevel is false, and do not
+ emit XmlRootAttribute if isTopLevel is false and no arguments have been
+ added.
+ * SoapCodeExporter.cs: Added bool argument to GenerateClass and
+ GenerateEnum methods.
+ * MapCodeGenerator.cs: Added bool argument to GenerateClass and
+ GenerateEnum methods.
+
2006-05-03 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* SerializationCodeGenerator.cs: Allow generating serializer for
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
2006-05-15 15:05:21 UTC (rev 60709)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
2006-05-15 15:53:35 UTC (rev 60710)
@@ -92,18 +92,18 @@
ExportMembersMapCode (dummyClass,
(ClassMap)xmlMembersMapping.ObjectMap, xmlMembersMapping.Namespace, null);
}
- public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
+ public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping,
bool isTopLevel)
{
- ExportMapCode (xmlTypeMapping);
+ ExportMapCode (xmlTypeMapping, isTopLevel);
RemoveInclude (xmlTypeMapping);
}
- void ExportMapCode (XmlTypeMapping map)
+ void ExportMapCode (XmlTypeMapping map, bool isTopLevel)
{
switch (map.TypeData.SchemaType)
{
case SchemaTypes.Enum:
- ExportEnumCode (map);
+ ExportEnumCode (map, isTopLevel);
break;
case SchemaTypes.Array:
@@ -111,7 +111,7 @@
break;
case SchemaTypes.Class:
- ExportClassCode (map);
+ ExportClassCode (map, isTopLevel);
break;
case SchemaTypes.XmlSerializable:
@@ -122,16 +122,18 @@
}
}
- void ExportClassCode (XmlTypeMapping map)
+ void ExportClassCode (XmlTypeMapping map, bool isTopLevel)
{
CodeTypeDeclaration codeClass;
-
if (IsMapExported (map)) {
- // Regenerate attributes, since things may have
changed
codeClass = GetMapDeclaration (map);
if (codeClass != null) {
- codeClass.CustomAttributes = null;
- GenerateClass (map, codeClass);
+ // Regenerate attributes, since things
may have changed
+ codeClass.CustomAttributes.Clear ();
+#if NET_2_0
+ AddClassAttributes (codeClass);
+#endif
+ GenerateClass (map, codeClass,
isTopLevel);
ExportDerivedTypeAttributes (map,
codeClass);
}
return;
@@ -143,7 +145,7 @@
SetMapExported (map, null);
foreach (XmlTypeMapping dmap in
exportedAnyType.DerivedTypes) {
if (IsMapExported (dmap) ||
!dmap.IncludeInSchema) continue;
- ExportTypeMapping (dmap);
+ ExportTypeMapping (dmap, false);
AddInclude (dmap);
}
return;
@@ -157,28 +159,10 @@
#if NET_2_0
codeClass.IsPartial =
CodeGenerator.Supports(GeneratorSupport.PartialTypes);
-
- CodeAttributeDeclaration generatedCodeAttribute = new
CodeAttributeDeclaration (
- new CodeTypeReference
(typeof(GeneratedCodeAttribute)));
- generatedCodeAttribute.Arguments.Add (new
CodeAttributeArgument (
- new CodePrimitiveExpression ("System.Xml")));
- generatedCodeAttribute.Arguments.Add (new
CodeAttributeArgument (
- new CodePrimitiveExpression ("2.0.50727.42")));
- codeClass.CustomAttributes.Add (generatedCodeAttribute);
-
- codeClass.CustomAttributes.Add (new
CodeAttributeDeclaration (
- new CodeTypeReference (typeof
(SerializableAttribute))));
- codeClass.CustomAttributes.Add (new
CodeAttributeDeclaration (
- new CodeTypeReference (typeof
(DebuggerStepThroughAttribute))));
-
- CodeAttributeDeclaration designerCategoryAttribute =
new CodeAttributeDeclaration (
- new CodeTypeReference
(typeof(DesignerCategoryAttribute)));
- designerCategoryAttribute.Arguments.Add (new
CodeAttributeArgument (
- new CodePrimitiveExpression ("code")));
- codeClass.CustomAttributes.Add
(designerCategoryAttribute);
+ AddClassAttributes (codeClass);
#endif
- GenerateClass (map, codeClass);
+ GenerateClass (map, codeClass, isTopLevel);
ExportDerivedTypeAttributes (map, codeClass);
ExportMembersMapCode (codeClass,
(ClassMap)map.ObjectMap, map.XmlTypeNamespace, map.BaseMap);
@@ -188,7 +172,7 @@
CodeTypeReference ctr = new CodeTypeReference
(map.BaseMap.TypeData.FullTypeName);
codeClass.BaseTypes.Add (ctr);
if (map.BaseMap.IncludeInSchema) {
- ExportMapCode (map.BaseMap);
+ ExportMapCode (map.BaseMap, false);
AddInclude (map.BaseMap);
}
}
@@ -211,7 +195,7 @@
if (codeClass.CustomAttributes == null)
codeClass.CustomAttributes = new
CodeAttributeDeclarationCollection ();
- ExportMapCode (tm);
+ ExportMapCode (tm, false);
ExportDerivedTypes (tm, codeClass);
}
}
@@ -332,7 +316,7 @@
if (attributes.Count > 0) codeField.CustomAttributes =
attributes;
if (attinfo.MappedType != null) {
- ExportMapCode (attinfo.MappedType);
+ ExportMapCode (attinfo.MappedType, false);
RemoveInclude (attinfo.MappedType);
}
@@ -385,7 +369,7 @@
GenerateElementInfoMember (attributes, member,
einfo, defaultType, defaultNamespace, addAlwaysAttr, forceUseMemberName);
if (einfo.MappedType != null) {
- ExportMapCode (einfo.MappedType);
+ ExportMapCode (einfo.MappedType, false);
RemoveInclude (einfo.MappedType);
}
}
@@ -444,7 +428,7 @@
if (ainfo.MappedType != null) {
if (!IsMapExported (ainfo.MappedType)
&& includeArrayTypes)
AddInclude (ainfo.MappedType);
- ExportMapCode (ainfo.MappedType);
+ ExportMapCode (ainfo.MappedType, false);
}
}
@@ -463,7 +447,7 @@
if (ainfo.MappedType != null) {
if (!IsMapExported (ainfo.MappedType)
&& includeArrayTypes)
AddInclude (ainfo.MappedType);
- ExportMapCode (ainfo.MappedType);
+ ExportMapCode (ainfo.MappedType, false);
}
}
}
@@ -481,7 +465,7 @@
return false;
}
- void ExportEnumCode (XmlTypeMapping map)
+ void ExportEnumCode (XmlTypeMapping map, bool isTopLevel)
{
if (IsMapExported (map)) return;
@@ -509,7 +493,7 @@
new CodeTypeReference (typeof
(SerializableAttribute))));
#endif
- GenerateEnum (map, codeEnum);
+ GenerateEnum (map, codeEnum, isTopLevel);
int flag = 1;
foreach (EnumMap.EnumMapMember emem in emap.Members)
@@ -603,6 +587,30 @@
AddComments (type, comments);
codeNamespace.Types.Add (type);
}
+
+#if NET_2_0
+ void AddClassAttributes (CodeTypeDeclaration codeClass)
+ {
+ CodeAttributeDeclaration generatedCodeAttribute = new
CodeAttributeDeclaration (
+ new CodeTypeReference (typeof
(GeneratedCodeAttribute)));
+ generatedCodeAttribute.Arguments.Add (new
CodeAttributeArgument (
+ new CodePrimitiveExpression ("System.Xml")));
+ generatedCodeAttribute.Arguments.Add (new
CodeAttributeArgument (
+ new CodePrimitiveExpression ("2.0.50727.42")));
+ codeClass.CustomAttributes.Add (generatedCodeAttribute);
+
+ codeClass.CustomAttributes.Add (new
CodeAttributeDeclaration (
+ new CodeTypeReference (typeof
(SerializableAttribute))));
+ codeClass.CustomAttributes.Add (new
CodeAttributeDeclaration (
+ new CodeTypeReference (typeof
(DebuggerStepThroughAttribute))));
+
+ CodeAttributeDeclaration designerCategoryAttribute =
new CodeAttributeDeclaration (
+ new CodeTypeReference (typeof
(DesignerCategoryAttribute)));
+ designerCategoryAttribute.Arguments.Add (new
CodeAttributeArgument (
+ new CodePrimitiveExpression ("code")));
+ codeClass.CustomAttributes.Add
(designerCategoryAttribute);
+ }
+#endif
CodeTypeReference GetDomType (TypeData data)
{
@@ -631,7 +639,7 @@
#region Overridable methods
- protected virtual void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass)
+ protected virtual void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass, bool isTopLevel)
{
}
@@ -691,8 +699,8 @@
protected virtual void GenerateUnnamedAnyElementAttribute
(CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo,
string defaultNamespace)
{
}
-
- protected virtual void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum)
+
+ protected virtual void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum, bool isTopLevel)
{
}
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
2006-05-15 15:05:21 UTC (rev 60709)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
2006-05-15 15:53:35 UTC (rev 60710)
@@ -129,7 +129,7 @@
public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
{
- codeGenerator.ExportTypeMapping (xmlTypeMapping);
+ codeGenerator.ExportTypeMapping (xmlTypeMapping, true);
}
@@ -148,8 +148,8 @@
: base (codeNamespace, codeCompileUnit, codeGen, options,
mappings)
{
}
-
- protected override void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass)
+
+ protected override void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass, bool isTopLevel)
{
CodeAttributeDeclaration att = new
CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");
if (map.XmlType != map.TypeData.TypeName)
att.Arguments.Add (GetArg (map.XmlType));
@@ -181,8 +181,8 @@
if
(!TypeTranslator.IsDefaultPrimitiveTpeData(einfo.TypeData)) att.Arguments.Add
(GetArg ("DataType",einfo.TypeData.XmlType));
if (addAlwaysAttr || att.Arguments.Count > 0)
attributes.Add (att);
}
-
- protected override void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum)
+
+ protected override void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum, bool isTopLevel)
{
CodeAttributeDeclaration att = new
CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");
if (map.XmlType != map.TypeData.TypeName)
att.Arguments.Add (GetArg (map.XmlType));
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
2006-05-15 15:05:21 UTC (rev 60709)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
2006-05-15 15:53:35 UTC (rev 60710)
@@ -176,7 +176,7 @@
public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
{
- codeGenerator.ExportTypeMapping (xmlTypeMapping);
+ codeGenerator.ExportTypeMapping (xmlTypeMapping, true);
}
#endregion // Methods
@@ -194,7 +194,7 @@
{
}
- protected override void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass)
+ protected override void GenerateClass (XmlTypeMapping map,
CodeTypeDeclaration codeClass, bool isTopLevel)
{
CodeAttributeDeclaration att = new
CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");
if (map.XmlType != map.TypeData.TypeName)
att.Arguments.Add (GetArg (map.XmlType));
@@ -204,9 +204,14 @@
CodeAttributeDeclaration ratt = new
CodeAttributeDeclaration ("System.Xml.Serialization.XmlRootAttribute");
if (map.ElementName != map.XmlType) ratt.Arguments.Add
(GetArg (map.ElementName));
- ratt.Arguments.Add (GetArg ("Namespace",
map.Namespace));
- ratt.Arguments.Add (GetArg ("IsNullable",
map.IsNullable));
- AddCustomAttribute (codeClass, ratt, false);
+ if (isTopLevel) {
+ ratt.Arguments.Add (GetArg ("Namespace",
map.Namespace));
+ ratt.Arguments.Add (GetArg ("IsNullable",
map.IsNullable));
+ } else {
+ if (map.Namespace != "")
+ ratt.Arguments.Add (GetArg
("Namespace", map.Namespace));
+ }
+ AddCustomAttribute (codeClass, ratt, isTopLevel);
}
protected override void GenerateClassInclude
(CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
@@ -299,10 +304,10 @@
if (einfo.Namespace != defaultNamespace)
uatt.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
attributes.Add (uatt);
}
-
- protected override void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum)
+
+ protected override void GenerateEnum (XmlTypeMapping map,
CodeTypeDeclaration codeEnum, bool isTopLevel)
{
- GenerateClass (map, codeEnum);
+ GenerateClass (map, codeEnum, isTopLevel);
}
protected override void GenerateEnumItem (CodeMemberField
codeField, EnumMap.EnumMapMember emem)
Modified: trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2006-05-15 15:05:21 UTC (rev 60709)
+++ trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2006-05-15 15:53:35 UTC (rev 60710)
@@ -1,3 +1,8 @@
+2006-05-15 Gert Driesen <[EMAIL PROTECTED]>
+
+ * XmlCodeExporterTests.cs: Added tests for arrays. Fixed usage of
+ XmlRootAttribute in tests.
+
2006-04-26 Gert Driesen <[EMAIL PROTECTED]>
* SoapSchemaExporterTests.cs: Sync expected results with changes to
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlCodeExporterTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlCodeExporterTests.cs
2006-05-15 15:05:21 UTC (rev 60709)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlCodeExporterTests.cs
2006-05-15 15:53:35 UTC (rev 60710)
@@ -69,6 +69,41 @@
" public object names;{0}" +
#endif
"}}{0}", Environment.NewLine), sw.ToString (),
"#2");
+
+ codeNamespace = ExportCode (typeof (ArrayClass[]));
+ Assert.IsNotNull (codeNamespace, "#3");
+
+ sw.GetStringBuilder ().Length = 0;
+ generator.GenerateCodeFromNamespace (codeNamespace, sw,
new CodeGeneratorOptions ());
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}{0}" +
+ "/// <remarks/>{0}" +
+#if NET_2_0
+
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\",
\"2.0.50727.42\")]{0}" +
+ "[System.SerializableAttribute()]{0}" +
+
"[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
+
"[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
+ "public partial class ArrayClass {{{0}" +
+ " {0}" +
+ " private object namesField;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " public object names {{{0}" +
+ " get {{{0}" +
+ " return this.namesField;{0}" +
+ " }}{0}" +
+ " set {{{0}" +
+ " this.namesField = value;{0}" +
+ " }}{0}" +
+ " }}{0}" +
+#else
+ "public class ArrayClass {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " public object names;{0}" +
+#endif
+ "}}{0}", Environment.NewLine), sw.ToString (), "#4");
}
[Test]
@@ -213,8 +248,6 @@
[Test]
#if NET_2_0
[Category ("NotDotNet")] // regression in MS.NET 2.0
-#else
- [Category ("NotDotNet")] // // Mono outputs XmlRootAttribute
for member types too
#endif
[Category ("NotWorking")] // TODO: order of
DefaultValueAttribute, ...
public void ExportTypeMapping_Field ()
@@ -448,7 +481,6 @@
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\",
\"2.0.50727.42\")]{0}" +
"[System.SerializableAttribute()]{0}" +
#endif
-
"[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=false)]{0}" +
"public enum FlagEnum {{{0}" +
" {0}" +
" /// <remarks/>{0}" +
@@ -470,7 +502,6 @@
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\",
\"2.0.50727.42\")]{0}" +
"[System.SerializableAttribute()]{0}" +
#endif
-
"[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=false)]{0}" +
"public enum MapModifiers {{{0}" +
" {0}" +
" /// <remarks/>{0}" +
@@ -515,10 +546,36 @@
" /// <remarks/>{0}" +
" ChoiceTwo,{0}" +
"}}{0}", Environment.NewLine), sw.ToString (),
"#2");
+
+ codeNamespace = ExportCode (typeof (ItemChoiceType[]));
+ Assert.IsNotNull (codeNamespace, "#3");
+
+ sw.GetStringBuilder ().Length = 0;
+ generator.GenerateCodeFromNamespace (codeNamespace, sw,
new CodeGeneratorOptions ());
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}{0}" +
+ "/// <remarks/>{0}" +
+#if NET_2_0
+
"[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\",
\"2.0.50727.42\")]{0}" +
+ "[System.SerializableAttribute()]{0}" +
+#endif
+
"[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
+ "public enum ItemChoiceType {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " ChoiceZero,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
+ " StrangeOne,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " ChoiceTwo,{0}" +
+ "}}{0}", Environment.NewLine), sw.ToString (),
"#4");
}
[Test]
- [Category ("NotDotNet")] // // Mono outputs XmlRootAttribute
for member types too
public void ExportTypeMapping_ClassArrayContainer ()
{
CodeNamespace codeNamespace = ExportCode (typeof
(ClassArrayContainer));
@@ -558,7 +615,6 @@
"[System.SerializableAttribute()]{0}" +
"[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
"[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
-
"[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=true)]{0}" +
"public partial class SimpleClass {{{0}" +
" {0}" +
" private string somethingField;{0}" +
@@ -573,7 +629,7 @@
" }}{0}" +
" }}{0}" +
#else
- "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=true)]{0}" +
+
"[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=true)]{0}" +
"public class ClassArrayContainer {{{0}" +
" {0}" +
" /// <remarks/>{0}" +
@@ -581,7 +637,6 @@
"}}{0}" +
"{0}" +
"/// <remarks/>{0}" +
-
"[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\",
IsNullable=true)]{0}" +
"public class SimpleClass {{{0}" +
" {0}" +
" /// <remarks/>{0}" +
@@ -591,6 +646,148 @@
}
[Test]
+#if NET_2_0
+ [Category ("NotDotNet")] // regression in MS.NET 2.0
+#endif
+ [Category ("NotWorking")] // bug #78214
+ public void ExportTypeMapping_Root ()
+ {
+ CodeNamespace codeNamespace = ExportCode (typeof
(Root));
+ Assert.IsNotNull (codeNamespace, "#1");
+
+ StringWriter sw = new StringWriter ();
+ CodeDomProvider provider = new CSharpCodeProvider ();
+ ICodeGenerator generator = provider.CreateGenerator ();
+ generator.GenerateCodeFromNamespace (codeNamespace, sw,
new CodeGeneratorOptions ());
+
+ Assert.AreEqual (string.Format
(CultureInfo.InvariantCulture,
+ "{0}{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
+
"[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\",
IsNullable=false)]{0}" +
+ "public class Root {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " public
MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " public
MonoTests.System.Xml.TestClasses.TestDefault Default;{0}" +
+ "}}{0}" +
+ "{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\",
Namespace=\"some:urn\")]{0}" +
+ "public class OptionalValueTypeContainer {{{0}"
+
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1
| MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
+ " public
MonoTests.System.Xml.TestClasses.FlagEnum Attributes =
(MonoTests.System.Xml.TestClasses.FlagEnum.e1 |
MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}"
+
+ " public
MonoTests.System.Xml.TestClasses.FlagEnum Flags =
MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
+ " public bool FlagsSpecified;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(false)]{0}" +
+ " public bool IsEmpty = false;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
+ " public bool IsEmptySpecified;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(false)]{0}" +
+ " public bool IsNull = false;{0}" +
+ "}}{0}" +
+ "{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
+ "[System.FlagsAttribute()]{0}" +
+ "public enum FlagEnum {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
+ " e1 = 1,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
+ " e2 = 2,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
+ " e4 = 4,{0}" +
+ "}}{0}" +
+ "{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
+ "public class TestDefault {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " public string str;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(\"Default Value\")]{0}" +
+ " public string strDefault = \"Default
Value\";{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(true)]{0}" +
+ " public bool boolT = true;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(false)]{0}" +
+ " public bool boolF = false;{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute(typeof(System.Decimal),
\"10\")]{0}" +
+ " public System.Decimal decimalval =
((System.Decimal)(10m));{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1
| MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
+ " public
MonoTests.System.Xml.TestClasses.FlagEnum flag =
(MonoTests.System.Xml.TestClasses.FlagEnum.e1 |
MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1
| MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4))]{0}" +
+ " public
MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded =
(MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 |
MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
+ "}}{0}" +
+ "{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
+ "[System.FlagsAttribute()]{0}" +
+ "public enum FlagEnum {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
+ " e1 = 1,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
+ " e2 = 2,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ "
[System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
+ " e4 = 4,{0}" +
+ "}}{0}" +
+ "{0}" +
+ "/// <remarks/>{0}" +
+
"[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
+ "[System.FlagsAttribute()]{0}" +
+ "public enum FlagEnum_Encoded {{{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " e1 = 1,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " e2 = 2,{0}" +
+ " {0}" +
+ " /// <remarks/>{0}" +
+ " e4 = 4,{0}" +
+ "}}{0}", Environment.NewLine), sw.ToString (),
"#2");
+ }
+
+ [Test]
public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
{
CodeNamespace codeNamespace = ExportCode (typeof
(SimpleClassWithXmlAttributes));
@@ -636,6 +833,42 @@
}
[Test]
+ public void ExportTypeMapping_XsdPrimitive_Arrays ()
+ {
+ ArrayList types = new ArrayList ();
+ types.Add (typeof (sbyte[]));
+ types.Add (typeof (bool[]));
+ types.Add (typeof (short[]));
+ types.Add (typeof (int[]));
+ types.Add (typeof (long[]));
+ types.Add (typeof (float[]));
+ types.Add (typeof (double[]));
+ types.Add (typeof (decimal[]));
+ types.Add (typeof (ushort[]));
+ types.Add (typeof (uint[]));
+ types.Add (typeof (ulong[]));
+ types.Add (typeof (DateTime[]));
+ types.Add (typeof (XmlQualifiedName[]));
+ types.Add (typeof (string[]));
+
+ StringWriter sw = new StringWriter ();
+ CodeDomProvider provider = new CSharpCodeProvider ();
+ ICodeGenerator generator = provider.CreateGenerator ();
+
+ foreach (Type type in types) {
+ CodeNamespace codeNamespace = ExportCode (type);
+ Assert.IsNotNull (codeNamespace, type.FullName
+ "#1");
+
+ generator.GenerateCodeFromNamespace
(codeNamespace, sw, new CodeGeneratorOptions ());
+
+ Assert.AreEqual (Environment.NewLine,
sw.ToString (),
+ type.FullName + "#2");
+
+ sw.GetStringBuilder ().Length = 0;
+ }
+ }
+
+ [Test]
public void ExportTypeMapping_ZeroFlagEnum ()
{
CodeNamespace codeNamespace = ExportCode (typeof
(ZeroFlagEnum));
@@ -680,5 +913,12 @@
exp.ExportTypeMapping (map);
return codeNamespace;
}
+
+ [XmlRootAttribute ("root", Namespace="urn:aNS",
IsNullable=false)]
+ public class Root
+ {
+ public OptionalValueTypeContainer OptionalValue;
+ public TestDefault Default;
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches