Imported Upstream version 3.12.0

Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
Jo Shields
2015-01-13 10:44:36 +00:00
parent 8b9b85e7f5
commit 181b81b4a4
659 changed files with 12743 additions and 16300 deletions

View File

@ -120,6 +120,10 @@ namespace System.Xml.Serialization
return;
}
var obExpectedType = typeMap.TypeData.Type;
if (!ob.GetType().IsAssignableFrom (obExpectedType))
ob = ImplicitConvert (ob, obExpectedType);
XmlTypeMapping map = typeMap.GetRealTypeMap (ob.GetType());
if (map == null)
@ -355,20 +359,19 @@ namespace System.Xml.Serialization
}
}
object ImplicitConvert (object obj, Type type)
internal static object ImplicitConvert (object obj, Type type)
{
if (obj == null)
return null;
for (Type t = type; t != typeof (object); t = t.BaseType) {
MethodInfo mi = t.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType.IsAssignableFrom (obj.GetType ()))
return mi.Invoke (null, new object [] {obj});
}
for (Type t = obj.GetType (); t != typeof (object); t = t.BaseType) {
MethodInfo mi = t.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType == type)
return mi.Invoke (null, new object [] {obj});
mi = type.GetMethod ("op_Implicit", new Type [] {t});
if (mi != null && mi.ReturnType == type)
return mi.Invoke (null, new object [] {obj});
}
return obj;
}