Fix incompatible hax conversion (1/2->3 etc) error

Shared base classes throw a new snag, where the property may be Declared
in the shared class.

eg:
PKM -> _K12 -> PK2

just filter all public ones that have a setter; works well enough idk
This commit is contained in:
Kurt 2019-05-28 16:52:59 -07:00
parent a45cddd3ed
commit 513648638f

View file

@ -1052,14 +1052,16 @@ namespace PKHeX.Core
public void TransferPropertiesWithReflection(PKM Destination)
{
// Only transfer declared properties not defined in PKM.cs but in the actual type
var SourceProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(GetType());
var DestinationProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(Destination.GetType());
var src_t = GetType();
var dst_t = Destination.GetType();
var SourceProperties = ReflectUtil.GetAllPropertyInfoPublic(src_t).Select(z => z.Name);
var DestinationProperties = ReflectUtil.GetAllPropertyInfoPublic(dst_t).Where(z => z.SetMethod != null).Select(z => z.Name);
// Transfer properties in the order they are defined in the destination PKM format for best conversion
var shared = DestinationProperties.Intersect(SourceProperties);
foreach (string property in shared)
{
BatchEditing.TryGetHasProperty(Destination, property, out var src);
BatchEditing.TryGetHasProperty(this, property, out var src);
var prop = src.GetValue(this);
if (prop != null && !(prop is byte[]) && BatchEditing.TryGetHasProperty(Destination, property, out var pi))
ReflectUtil.SetValue(pi, Destination, prop);