};
#if NET_2_0
- private Type GetGenericListItemType (Type type)
+ internal static Type GetGenericListItemType (Type type)
{
- if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (ICollection<>))
- return type.GetGenericArguments () [0];
+ if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (IEnumerable<>)) {
+ Type [] gatypes = type.GetGenericArguments ();
+ if (type.GetMethod ("Add", gatypes) != null)
+ return gatypes [0];
+ }
Type t = null;
foreach (Type i in type.GetInterfaces ())
if ((t = GetGenericListItemType (i)) != null)
XmlAttributes atts = attributeOverrides[type, prop.Name];
if (atts == null) atts = new XmlAttributes (prop);
if (atts.XmlIgnore) continue;
- if (!prop.CanWrite && (TypeTranslator.GetTypeData (prop.PropertyType).SchemaType != SchemaTypes.Array || prop.PropertyType.IsArray)) continue;
+ if (!prop.CanWrite) {
+ if (prop.PropertyType.IsGenericType && TypeData.GetGenericListItemType (prop.PropertyType) == null) continue; // check this before calling GetTypeData() which raises error for missing Add(). See bug #704813.
+ if (TypeTranslator.GetTypeData (prop.PropertyType).SchemaType != SchemaTypes.Array || prop.PropertyType.IsArray) continue;
+ }
XmlReflectionMember member = new XmlReflectionMember(prop.Name, prop.PropertyType, atts);
member.DeclaringType = prop.DeclaringType;
members.Add(member);
using System;
using System.Collections;
+using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
{
new XmlSerializer (typeof (MyCollection));
}
+
+ [Test]
+ public void Bug704813Type ()
+ {
+ var xs = new XmlSerializer (typeof (Bug704813Type));
+ xs.Serialize (TextWriter.Null, new Bug704813Type ());
+ }
#endif
public class Employee : IXmlSerializable
{
}
}
+
+ public class Bug704813Type
+ {
+ IEnumerable<string> foo = new List<string> ();
+ public IEnumerable<string> Foo {
+ get { return foo; }
+ }
+ }
}