internal static QName GetContractQName (Type type, string name, string ns)
{
- if (name == null)
+ if (name == null) {
// FIXME: there could be decent ways to get
// the same result...
name = type.Namespace == null || type.Namespace.Length == 0 ? type.Name : type.FullName.Substring (type.Namespace.Length + 1).Replace ('+', '.');
-
+ if (type.IsGenericType) {
+ name = name.Substring (0, name.IndexOf ('`')) + "Of";
+ foreach (var t in type.GetGenericArguments ())
+ name += t.Name; // FIXME: check namespaces too
+ }
+ }
if (ns == null)
ns = XmlObjectSerializer.DefaultNamespaceBase + type.Namespace;
return new QName (name, ns);
private QName GetSerializableQName (Type type)
{
string xmlName = type.Name;
+ if (type.IsGenericType) {
+ xmlName = xmlName.Substring (0, xmlName.IndexOf ('`')) + "Of";
+ foreach (var t in type.GetGenericArguments ())
+ xmlName += t.Name; // FIXME: check namespaces too
+ }
string xmlNamespace = XmlObjectSerializer.DefaultNamespaceBase + type.Namespace;
var x = GetAttribute<XmlRootAttribute> (type);
if (x != null) {
Assert.AreEqual (w.T, w.T2, "#2");
}
+ [Test]
+ public void GenericSerialization ()
+ {
+ var sw = new StringWriter ();
+ var ser = new DataContractSerializer (typeof (Foo<string,int,int>));
+ using (var xw = XmlWriter.Create (sw))
+ ser.WriteObject (xw, new Foo<string,int,int> () {Field = "f"
+ });
+ var s = sw.ToString ();
+
+ var ret = (Foo<string,int,int>) ser.ReadObject (XmlReader.Create (new StringReader (s)));
+ Assert.AreEqual ("f", ret.Field);
+ }
+
private T Deserialize<T> (string xml)
{
return Deserialize<T> (xml, typeof (T));
class GlobalSample1
{
}
+
+[DataContract]
+class Foo<X,Y,Z>
+{
+ [DataMember]
+ public X Field;
+}