Update XmlFormatter2.cs with setMethod handling and type comparison improvements
x) Added setMethod handling for child elements x) Improved type comparison using IsAssignableFrom instead of IsSubclassOf
This commit is contained in:
parent
13d86f73eb
commit
a5cd9b3a67
@ -648,14 +648,14 @@ namespace lib
|
|||||||
|
|
||||||
XmlElement childElem = getNamedChild( allChildren, name );
|
XmlElement childElem = getNamedChild( allChildren, name );
|
||||||
|
|
||||||
|
var setMethod = childPi.GetSetMethod();
|
||||||
|
|
||||||
if( childElem != null )
|
if( childElem != null )
|
||||||
{
|
{
|
||||||
object existingObj = childPi.GetValue( obj );
|
object existingObj = childPi.GetValue( obj );
|
||||||
|
|
||||||
object childObj = Deserialize( childElem, childPi, childPi.PropertyType, existingObj );
|
object childObj = Deserialize( childElem, childPi, childPi.PropertyType, existingObj );
|
||||||
|
|
||||||
var setMethod = childPi.GetSetMethod();
|
|
||||||
|
|
||||||
if( setMethod != null )
|
if( setMethod != null )
|
||||||
{
|
{
|
||||||
//Object o = Activator.CreateInstance( setMethod.ReflectedType );
|
//Object o = Activator.CreateInstance( setMethod.ReflectedType );
|
||||||
@ -667,7 +667,24 @@ namespace lib
|
|||||||
{
|
{
|
||||||
childPi.SetValue( obj, childObj );
|
childPi.SetValue( obj, childObj );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object existingObj = childPi.GetValue( obj );
|
||||||
|
|
||||||
|
object childObj = DeserializeConcrete( elem, childPi, name, childPi.PropertyType );
|
||||||
|
|
||||||
|
if( setMethod != null )
|
||||||
|
{
|
||||||
|
//Object o = Activator.CreateInstance( setMethod.ReflectedType );
|
||||||
|
setMethod.Invoke( obj, new object[] { childObj } );
|
||||||
|
|
||||||
|
//setMethod.CreateDelegate()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
childPi.SetValue( obj, childObj );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -961,8 +978,9 @@ namespace lib
|
|||||||
{
|
{
|
||||||
var existingObjType = existingObj.GetType();
|
var existingObjType = existingObj.GetType();
|
||||||
|
|
||||||
// @@@ GROSS Fix the types so theyre known good.
|
//var isSubclass = type.IsSubclassOf( existingObjType ) || existingObjType.IsSubclassOf( type );
|
||||||
var isSubclass = type.IsSubclassOf( existingObjType ) || existingObjType.IsSubclassOf( type );
|
var isSubclass = type.IsAssignableFrom( existingObjType );
|
||||||
|
|
||||||
|
|
||||||
if( isSubclass )
|
if( isSubclass )
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user