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:
Marc Hernandez 2024-07-03 12:40:47 -07:00
parent 13d86f73eb
commit a5cd9b3a67

View File

@ -648,14 +648,14 @@ namespace lib
XmlElement childElem = getNamedChild( allChildren, name );
var setMethod = childPi.GetSetMethod();
if( childElem != null )
{
object existingObj = childPi.GetValue( obj );
object childObj = Deserialize( childElem, childPi, childPi.PropertyType, existingObj );
var setMethod = childPi.GetSetMethod();
if( setMethod != null )
{
//Object o = Activator.CreateInstance( setMethod.ReflectedType );
@ -667,7 +667,24 @@ namespace lib
{
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();
// @@@ 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 )
{