* KnownTypeCollection.cs : support DataContractNamespaceAttribute.
Fixed bug #599889.
* XmlObjectSerializerTest.cs : add test for bug #599899.
svn path=/trunk/mcs/; revision=156277
+2010-04-28 Atsushi Enomoto <atsushi@ximian.com>
+
+ * KnownTypeCollection.cs : support DataContractNamespaceAttribute.
+ Fixed bug #599889.
+
2010-04-05 Atsushi Enomoto <atsushi@ximian.com>
* DataContractExporter-new.cs : do not expect contract attribute on
}
}
if (ns == null)
- ns = DefaultClrNamespaceBase + type.Namespace;
+ ns = GetDefaultNamespace (type);
return new QName (name, ns);
}
}
if (ns == null)
- ns = DefaultClrNamespaceBase + type.Namespace;
+ ns = GetDefaultNamespace (type);
if (name == null)
name = type.Namespace == null ? type.Name : type.FullName.Substring (type.Namespace.Length + 1).Replace ('+', '.');
return new QName (name, ns);
}
+ static string GetDefaultNamespace (Type type)
+ {
+ foreach (ContractNamespaceAttribute a in type.Assembly.GetCustomAttributes (typeof (ContractNamespaceAttribute), true))
+ if (a.ClrNamespace == type.Namespace)
+ return a.ContractNamespace;
+ return DefaultClrNamespaceBase + type.Namespace;
+ }
+
static QName GetCollectionQName (Type element)
{
QName eqname = GetStaticQName (element);
foreach (var t in type.GetGenericArguments ())
xmlName += GetStaticQName (t).Name; // FIXME: check namespaces too
}
- string xmlNamespace = DefaultClrNamespaceBase + type.Namespace;
+ string xmlNamespace = GetDefaultNamespace (type);
var x = GetAttribute<XmlRootAttribute> (type);
if (x != null) {
xmlName = x.ElementName;
return null;
}
- internal static T GetAttribute<T> (MemberInfo mi) where T : Attribute
+ internal static T GetAttribute<T> (ICustomAttributeProvider ap) where T : Attribute
{
- object [] atts = mi.GetCustomAttributes (typeof (T), false);
+ object [] atts = ap.GetCustomAttributes (typeof (T), false);
return atts.Length == 0 ? null : (T) atts [0];
}
+2010-04-28 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlObjectSerializerTest.cs : add test for bug #599899.
+
2010-03-04 Atsushi Enomoto <atsushi@ximian.com>
* XmlObjectSerializerTest.cs : test for empty array deserialization.
using System.Xml.Serialization;
using System.Xml.Schema;
+[assembly: ContractNamespace ("http://www.u2u.be/samples/wcf/2009", ClrNamespace = "U2U.DataContracts")] // bug #599889
+
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
var ret = ds.ReadObject (xr);
Assert.AreEqual (typeof (string []), ret.GetType (), "#1");
}
+
+ [Test]
+ public void ContractNamespaceAttribute ()
+ {
+ var ds = new DataContractSerializer (typeof (U2U.DataContracts.Person));
+ string xml = "<?xml version='1.0' encoding='utf-16'?><Person xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.u2u.be/samples/wcf/2009'><Name>Rupert</Name><Occupation><Description>Monkey</Description></Occupation></Person>";
+ var person = new U2U.DataContracts.Person () {
+ Name = "Rupert",
+ Occupation = new U2U.DataContracts.Job () { Description = "Monkey" }
+ };
+ var sw = new StringWriter ();
+ using (var xw = XmlWriter.Create (sw))
+ ds.WriteObject (xw, person);
+ Assert.AreEqual (xml, sw.ToString ().Replace ('"', '\''), "#1");
+ }
}
[DataContract]
return string.Format ("name={0},id={1}", name, Id);
}
}
+
+// bug #599889
+namespace U2U.DataContracts
+{
+ [DataContract]
+ public class Person
+ {
+ [DataMember]
+ public string Name { get; set; }
+
+ [DataMember]
+ public Job Occupation { get; set; }
+ }
+
+ [DataContract]
+ public class Job
+ {
+ [DataMember]
+ public string Description { get; set; }
+ }
+}