From 513648638f7d52b2cd25f56cec63e7efb8ec3c23 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 28 May 2019 16:52:59 -0700 Subject: [PATCH] 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 --- PKHeX.Core/PKM/PKM.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 497422457..f7146dae7 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -1052,14 +1052,16 @@ public int GetFlawlessIVCount() 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);