Author: atsushi
Date: 2007-09-25 11:55:48 -0400 (Tue, 25 Sep 2007)
New Revision: 86340
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
Log:
2007-09-25 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlTypeMapping.cs, XmlSerializationWriterInterpreter.cs,
SerializationCodeGenerator.cs :
More XmlSchemaProviderAttribute method check. Use QName returned
by the method for the output root name.
* XmlSerializerTests.cs, XmlReflectionImporterTests.cs :
added tests for XmlSchemaProviderAttribute and how its qname works.
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2007-09-25 15:34:04 UTC (rev 86339)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2007-09-25 15:55:48 UTC (rev 86340)
@@ -1,3 +1,10 @@
+2007-09-25 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * 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 <[EMAIL PROTECTED]>
* XmlReflectionImporter.cs : do not reject XmlArrayAttribute on
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
===================================================================
---
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
2007-09-25 15:34:04 UTC (rev 86339)
+++
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
2007-09-25 15:55:48 UTC (rev 86340)
@@ -666,7 +666,9 @@
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 ("}");
@@ -2135,7 +2137,7 @@
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");
@@ -2431,7 +2433,7 @@
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 ("}");
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
===================================================================
---
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
2007-09-25 15:34:04 UTC (rev 86339)
+++
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
2007-09-25 15:55:48 UTC (rev 86340)
@@ -116,7 +116,7 @@
if (typeMap.TypeData.SchemaType ==
SchemaTypes.XmlSerializable)
{
- WriteSerializable ((IXmlSerializable)ob,
element, namesp, isNullable);
+ WriteSerializable ((IXmlSerializable)ob,
typeMap.XmlType ?? element, typeMap.XmlTypeNamespace ?? namesp, isNullable);
return;
}
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
2007-09-25 15:34:04 UTC (rev 86339)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
2007-09-25 15:55:48 UTC (rev 86340)
@@ -205,6 +205,13 @@
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;
Modified: trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2007-09-25 15:34:04 UTC (rev 86339)
+++ trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
2007-09-25 15:55:48 UTC (rev 86340)
@@ -1,3 +1,8 @@
+2007-09-25 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlSerializerTests.cs, XmlReflectionImporterTests.cs :
+ added tests for XmlSchemaProviderAttribute and how its qname works.
+
2007-08-21 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlReflectionImporterTest.cs : test for bug #81880.
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
2007-09-25 15:34:04 UTC (rev 86339)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlReflectionImporterTests.cs
2007-09-25 15:55:48 UTC (rev 86340)
@@ -1590,6 +1590,27 @@
{
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
@@ -2081,6 +2102,67 @@
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
}
}
Modified:
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
===================================================================
---
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
2007-09-25 15:34:04 UTC (rev 86339)
+++
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs
2007-09-25 15:55:48 UTC (rev 86340)
@@ -2662,6 +2662,14 @@
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
@@ -2760,6 +2768,33 @@
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)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches