+2007-09-25 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlTypeMapping.cs, XmlSerializationWriterInterpreter.cs,
+ SerializationCodeGenerator.cs :
+ More XmlSchemaProviderAttribute method check. Use QName returned
+ by the method for the output root name.
+
2007-08-21 Atsushi Enomoto <atsushi@ximian.com>
* XmlReflectionImporter.cs : do not reject XmlArrayAttribute on
if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
{
- WriteLine ("WriteSerializable (ob, element, namesp, isNullable);");
+ WriteLine (String.Format ("WriteSerializable (ob, {0}, {1}, isNullable);",
+ typeMap.XmlType != null ? GetLiteral (typeMap.XmlType) : "element",
+ typeMap.XmlTypeNamespace != null ? GetLiteral (typeMap.XmlTypeNamespace) : "namesp"));
GenerateEndHook ();
WriteLineUni ("}");
return GetReadObjectCall (elem.MappedType, GetLiteral(elem.IsNullable), "true");
case SchemaTypes.XmlSerializable:
- return GetCast (elem.TypeData, String.Format ("ReadSerializable (({0}) Activator.CreateInstance(typeof({0}), true))", elem.TypeData.CSharpFullName));
+ return GetCast (elem.TypeData, String.Format ("({0}) ReadSerializable (({0}) Activator.CreateInstance(typeof({0}), true))", elem.TypeData.CSharpFullName));
default:
throw new NotSupportedException ("Invalid value type");
WriteLine ("if (Reader.NodeType == XmlNodeType.Element)");
WriteLineInd ("{");
WriteLine ("if (Reader.LocalName == " + GetLiteral (typeMap.ElementName) + " && Reader.NamespaceURI == " + GetLiteral (typeMap.Namespace) + ")");
- WriteLine (String.Format ("\treturn ReadSerializable (({0}) Activator.CreateInstance(typeof({0}), true));", typeMap.TypeData.CSharpFullName));
+ WriteLine (String.Format ("\treturn ({0}) ReadSerializable (({0}) Activator.CreateInstance(typeof({0}), true));", typeMap.TypeData.CSharpFullName));
WriteLine ("else");
WriteLine ("\tthrow CreateUnknownNodeException ();");
WriteLineUni ("}");
if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
{
- WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable);
+ WriteSerializable ((IXmlSerializable)ob, typeMap.XmlType ?? element, typeMap.XmlTypeNamespace ?? namesp, isNullable);
return;
}
if (schemaProvider != null) {
string method = schemaProvider.MethodName;
MethodInfo mi = typeData.Type.GetMethod (method, BindingFlags.Static | BindingFlags.Public);
+ 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;
+2007-09-25 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlSerializerTests.cs, XmlReflectionImporterTests.cs :
+ added tests for XmlSchemaProviderAttribute and how its qname works.
+
2007-08-21 Atsushi Enomoto <atsushi@ximian.com>
* XmlReflectionImporterTest.cs : test for bug #81880.
{
new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
}
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMissingMethod ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMethodNonStatic ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMethodIncorrectReturn ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
+ }
#endif
public class Employee : IXmlSerializable
set { this.value = value; }
}
}
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderMissingMethodType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+ }
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderNonStaticType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+
+ public object GetXsdType ()
+ {
+ return null;
+ }
+ }
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+
+ public static object GetXsdType ()
+ {
+ return null;
+ }
+ }
#endif
}
}
xs.Serialize (sw, PrivateCtorOnly.Instance);
xs.Deserialize (new StringReader (sw.ToString ()));
}
+
+ [Test]
+ public void XmlSchemaProviderQNameBecomesRootName ()
+ {
+ xs = new XmlSerializer (typeof (XmlSchemaProviderQNameBecomesRootNameType));
+ Serialize (new XmlSchemaProviderQNameBecomesRootNameType ());
+ Assert.AreEqual (Infoset ("<foo />"), WriterText);
+ }
#endif
#endregion //GenericsSeralizationTests
get { return NullableInt.HasValue; }
}
}
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderQNameBecomesRootNameType : IXmlSerializable
+ {
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public static XmlQualifiedName GetXsdType (XmlSchemaSet xss)
+ {
+ XmlSchema xs = new XmlSchema ();
+ XmlSchemaComplexType ct = new XmlSchemaComplexType ();
+ ct.Name = "foo";
+ xs.Items.Add (ct);
+ xss.Add (xs);
+ return new XmlQualifiedName ("foo");
+ }
+ }
#endif
void CDataTextNodes_BadNode (object s, XmlNodeEventArgs e)