+#if NET_2_0 && !MOONLIGHT
+ XmlSchemaProviderAttribute schemaProvider = (XmlSchemaProviderAttribute) Attribute.GetCustomAttribute (typeData.Type, typeof (XmlSchemaProviderAttribute));
+
+ if (schemaProvider != null) {
+ string method = schemaProvider.MethodName;
+ MethodInfo mi = typeData.Type.GetMethod (method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
+ if (mi == null)
+ throw new InvalidOperationException (String.Format ("Type '{0}' must implement public static method '{1}'", typeData.Type, method));
+ if (!typeof (XmlQualifiedName).IsAssignableFrom (mi.ReturnType) &&
+ // LAMESPEC: it is undocumented. (We don't have to tell users about it in the error message.)
+ // Also do not add such a silly compatibility test to assert that it does not raise an error.
+ !typeof (XmlSchemaComplexType).IsAssignableFrom (mi.ReturnType))
+ 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;
+
+ if (retVal is XmlSchemaComplexType) {
+ _schemaType = (XmlSchemaComplexType) retVal;
+ if (!_schemaType.QualifiedName.IsEmpty)
+ _schemaTypeName = _schemaType.QualifiedName;
+ else
+ _schemaTypeName = new XmlQualifiedName (xmlType, xmlTypeNamespace);
+ }
+ else if (retVal is XmlQualifiedName) {
+ _schemaTypeName = (XmlQualifiedName)retVal;
+ }
+ else
+ throw new InvalidOperationException (
+ 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 (root != null ? root.ElementName : _schemaTypeName.Name, root != null ? root.Namespace : Namespace ?? _schemaTypeName.Namespace));
+ XmlTypeNamespace = _schemaTypeName.Namespace;
+ XmlType = _schemaTypeName.Name;
+
+ if (!_schemaTypeName.IsEmpty && xs.Count > 0) {
+ XmlSchema [] schemas = new XmlSchema [xs.Count];
+ xs.CopyTo (schemas, 0);
+ _schema = schemas [0];
+ }
+
+ 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);