Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@gmail.com>2008-11-05 14:54:29 +0300
committerAtsushi Eno <atsushieno@gmail.com>2008-11-05 14:54:29 +0300
commitae6c7511d16d695af43d08322eec2aabf10296b1 (patch)
treed38aa2d56598cf7b3c45944c5c3c207abe2a5ead /mcs/class/System.XML/System.Xml.Serialization
parent01890f8e997f0f93aab942ec3c150337d975b41e (diff)
Fix for bug #430759.
svn path=/trunk/mcs/; revision=117965
Diffstat (limited to 'mcs/class/System.XML/System.Xml.Serialization')
-rw-r--r--mcs/class/System.XML/System.Xml.Serialization/ChangeLog5
-rw-r--r--mcs/class/System.XML/System.Xml.Serialization/TypeData.cs28
2 files changed, 22 insertions, 11 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/ChangeLog b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
index b042772e430..ad0da11ac71 100644
--- a/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
+++ b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-05 Atsushi Enomoto <atsushi@ximian.com>
+
+ * TypeData.cs : do not reject ICollection<T> for not implementing
+ Item[T]. Fixed bug #430759.
+
2008-09-19 Atsushi Enomoto <atsushi@ximian.com>
* XmlSerializer.cs : revert previous change and fix sys.data tests.
diff --git a/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs b/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs
index 33fa38aef9d..00e9beb396e 100644
--- a/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs
+++ b/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs
@@ -285,12 +285,14 @@ namespace System.Xml.Serialization
if (listItemType != null) return listItemType;
+ Type genericArgument = null;
+
if (SchemaType != SchemaTypes.Array)
throw new InvalidOperationException (Type.FullName + " is not a collection");
else if (type.IsArray)
listItemType = type.GetElementType ();
#if NET_2_0
- else if (typeof (ICollection).IsAssignableFrom (type) || IsGenericList (type))
+ else if (typeof (ICollection).IsAssignableFrom (type) || (genericArgument = GetGenericListItemType (type)) != null)
#else
else if (typeof (ICollection).IsAssignableFrom (type))
#endif
@@ -300,11 +302,14 @@ namespace System.Xml.Serialization
"The type {0} is not supported because it implements" +
" IDictionary.", type.FullName));
- PropertyInfo prop = GetIndexerProperty (type);
- if (prop == null)
- throw new InvalidOperationException ("You must implement a default accessor on " + type.FullName + " because it inherits from ICollection");
-
- listItemType = prop.PropertyType;
+ if (genericArgument != null)
+ listItemType = genericArgument;
+ else {
+ PropertyInfo prop = GetIndexerProperty (type);
+ if (prop == null)
+ throw new InvalidOperationException ("You must implement a default accessor on " + type.FullName + " because it inherits from ICollection");
+ listItemType = prop.PropertyType;
+ }
MethodInfo addMethod = type.GetMethod ("Add", new Type[] { listItemType });
if (addMethod == null)
@@ -413,14 +418,15 @@ namespace System.Xml.Serialization
};
#if NET_2_0
- private bool IsGenericList (Type type)
+ private Type GetGenericListItemType (Type type)
{
if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (ICollection<>))
- return true;
+ return type.GetGenericArguments () [0];
+ Type t = null;
foreach (Type i in type.GetInterfaces ())
- if (IsGenericList (i))
- return true;
- return false;
+ if ((t = GetGenericListItemType (i)) != null)
+ return t;
+ return null;
}
#endif
}