Merge pull request #1275 from ranma42/fix-lib64
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlTypeMapping.cs
index 859042fd7e34d404f8bcc489a1cd91c5b3fc500a..533953b67f2fbf8936bc680ec94d7fd4a187cefc 100644 (file)
@@ -49,6 +49,7 @@ namespace System.Xml.Serialization
                string documentation;
                bool includeInSchema;
                bool isNullable = true;
+               bool isAny;
 
                ArrayList _derivedTypes = new ArrayList();
 
@@ -158,6 +159,12 @@ namespace System.Xml.Serialization
                        set { isNullable = value; }
                }
 
+               internal bool IsAny
+               {
+                       get { return isAny; }
+                       set { isAny = value; }
+               }
+
                internal XmlTypeMapping GetRealTypeMap (Type objectType)
                {
                        if (TypeData.SchemaType == SchemaTypes.Enum)
@@ -196,18 +203,22 @@ namespace System.Xml.Serialization
        internal class XmlSerializableMapping : XmlTypeMapping
        {
                XmlSchema _schema;
-#if NET_2_0 && !MOONLIGHT
                XmlSchemaComplexType _schemaType;
                XmlQualifiedName _schemaTypeName;
-#endif
 
                internal XmlSerializableMapping(XmlRootAttribute root, string elementName, string ns, TypeData typeData, string xmlType, string xmlTypeNamespace)
                        : base(elementName, ns, typeData, xmlType, xmlTypeNamespace)
                {
-#if NET_2_0 && !MOONLIGHT
                        XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute) Attribute.GetCustomAttribute (typeData.Type, typeof (XmlSchemaProviderAttribute));
 
                        if (schemaProvider != null) {
+                               _schemaTypeName = XmlQualifiedName.Empty;
+
+                               if (schemaProvider.IsAny) {
+                                       IsAny = true;
+                                       return;
+                               }
+
                                string method = schemaProvider.MethodName;
                                MethodInfo mi = typeData.Type.GetMethod (method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                                if (mi == null)
@@ -219,7 +230,6 @@ namespace System.Xml.Serialization
                                        throw new InvalidOperationException (String.Format ("Method '{0}' indicated by XmlSchemaProviderAttribute must have its return type as XmlQualifiedName", method));
                                XmlSchemaSet xs = new XmlSchemaSet ();
                                object retVal = mi.Invoke (null, new object [] { xs });
-                               _schemaTypeName = XmlQualifiedName.Empty;
                                if (retVal == null)
                                        return;
 
@@ -250,25 +260,19 @@ namespace System.Xml.Serialization
 
                                return;
                        }
-#endif
-#if NET_2_0 && !MOONLIGHT
+
                        IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type, true);
                        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
@@ -276,7 +280,6 @@ namespace System.Xml.Serialization
                        get { return _schema; }
                }
 
-#if NET_2_0 && !MOONLIGHT
                internal XmlSchemaType SchemaType {
                        get { return _schemaType; }
                }
@@ -284,7 +287,6 @@ namespace System.Xml.Serialization
                internal XmlQualifiedName SchemaTypeName {
                        get { return _schemaTypeName; }
                }
-#endif
        }
  
 
@@ -400,10 +402,26 @@ namespace System.Xml.Serialization
                        return (XmlTypeMapMemberAttribute)_attributeMembers [BuildKey (name,ns, -1)];
                }
 
-               public XmlTypeMapElementInfo GetElement (string name, string ns, int order)
+               public XmlTypeMapElementInfo GetElement(string name, string ns, int minimalOrder)
                {
                        if (_elements == null) return null;
-                       return (XmlTypeMapElementInfo)_elements [BuildKey (name,ns, order)];
+
+                       foreach (XmlTypeMapElementInfo info in _elements.Values)
+                               if (info.ElementName == name && info.Namespace == ns && info.ExplicitOrder >= minimalOrder)
+                                       return info;
+
+                       return null;
+               }
+
+               public XmlTypeMapElementInfo GetElement(string name, string ns)
+               {
+                       if (_elements == null) return null;
+
+                       foreach (XmlTypeMapElementInfo info in _elements.Values)
+                               if (info.ElementName == name && info.Namespace == ns)
+                                       return info;
+
+                       return null;
                }
                
                public XmlTypeMapElementInfo GetElement (int index)