[Web Services] Fix regression caused by previous commit
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlTypeMapping.cs
index 703bd82c51ae267de4b247e6250e02cd8c22f8ed..752aae73c27d514725370cccbed7de328bfba0b2 100644 (file)
@@ -191,15 +191,15 @@ namespace System.Xml.Serialization
        internal class XmlSerializableMapping : XmlTypeMapping
        {
                XmlSchema _schema;
-#if NET_2_0
+#if NET_2_0 && !MOONLIGHT
                XmlSchemaComplexType _schemaType;
                XmlQualifiedName _schemaTypeName;
 #endif
 
-               internal XmlSerializableMapping(string elementName, string ns, TypeData typeData, string xmlType, string xmlTypeNamespace)
+               internal XmlSerializableMapping(XmlRootAttribute root, string elementName, string ns, TypeData typeData, string xmlType, string xmlTypeNamespace)
                        : base(elementName, ns, typeData, xmlType, xmlTypeNamespace)
                {
-#if NET_2_0
+#if NET_2_0 && !MOONLIGHT
                        XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute) Attribute.GetCustomAttribute (typeData.Type, typeof (XmlSchemaProviderAttribute));
 
                        if (schemaProvider != null) {
@@ -233,7 +233,7 @@ namespace System.Xml.Serialization
                                                String.Format ("Method {0}.{1}() specified by XmlSchemaProviderAttribute has invalid signature: return type must be compatible with System.Xml.XmlQualifiedName.", typeData.Type.Name, method));
 
                                // defaultNamespace at XmlReflectionImporter takes precedence for Namespace, but not for XsdTypeNamespace.
-                               UpdateRoot (new XmlQualifiedName (_schemaTypeName.Name, Namespace ?? _schemaTypeName.Namespace));
+                               UpdateRoot (new XmlQualifiedName (root != null ? root.ElementName : _schemaTypeName.Name, root != null ? root.Namespace : Namespace ?? _schemaTypeName.Namespace));
                                XmlTypeNamespace = _schemaTypeName.Namespace;
                                XmlType = _schemaTypeName.Name;
 
@@ -246,21 +246,24 @@ namespace System.Xml.Serialization
                                return;
                        }
 #endif
+#if NET_2_0 && !MOONLIGHT
                        IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type, true);
-#if NET_2_0
                        try {
                                _schema = serializable.GetSchema();
                        } catch (Exception) {
                                // LAMESPEC: .NET has a bad exception catch and swallows it silently.
                        }
 #else
+                       IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type);
                        _schema = serializable.GetSchema();
 #endif
+#if !MOONLIGHT
                        if (_schema != null) 
                        {
                                if (_schema.Id == null || _schema.Id.Length == 0) 
                                        throw new InvalidOperationException("Schema Id is missing. The schema returned from " + typeData.Type.FullName + ".GetSchema() must have an Id.");
                        }
+#endif
                }
 
                internal XmlSchema Schema
@@ -268,7 +271,7 @@ namespace System.Xml.Serialization
                        get { return _schema; }
                }
 
-#if NET_2_0
+#if NET_2_0 && !MOONLIGHT
                internal XmlSchemaType SchemaType {
                        get { return _schemaType; }
                }
@@ -303,7 +306,10 @@ namespace System.Xml.Serialization
 
                public void AddMember (XmlTypeMapMember member)
                {
-                       member.GlobalIndex = _allMembers.Count;
+                       // If GlobalIndex has not been set, set it now
+                       if (member.GlobalIndex == -1)
+                               member.GlobalIndex = _allMembers.Count;
+                       
                        _allMembers.Add (member);
                        
                        if (!(member.DefaultValue is System.DBNull) && member.DefaultValue != null) {