From 118a213b6cfe2d42a135172457247feef53a67a3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 3 Feb 2018 15:32:45 -0800 Subject: [PATCH] Fix backwards conversion copy order reflection (now only used for backwards conversion) will use destination order instead of source order so that the destination can order itself for quirks redo method call (probably breaks someone if they update, maybe pk2pk) --- PKHeX.Core/PKM/PKM.cs | 12 +++++++----- PKHeX.Core/PKM/PKMConverter.cs | 7 +------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index e48d79f18..50248ddfb 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -902,16 +902,18 @@ public int GetFlawlessIVCount() } /// - /// Applies all shared properties from to . + /// Applies all shared properties from the current to . /// - /// that supplies property values. /// that receives property values. - public void TransferPropertiesWithReflection(PKM Source, PKM Destination) + public void TransferPropertiesWithReflection(PKM Destination) { // Only transfer declared properties not defined in PKM.cs but in the actual type - var SourceProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(Source.GetType()); + var SourceProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(GetType()); var DestinationProperties = ReflectUtil.GetPropertiesCanWritePublicDeclared(Destination.GetType()); - foreach (string property in SourceProperties.Intersect(DestinationProperties)) + + // 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) { var prop = ReflectUtil.GetValue(this, property); if (prop != null && !(prop is byte[])) diff --git a/PKHeX.Core/PKM/PKMConverter.cs b/PKHeX.Core/PKM/PKMConverter.cs index c94d6c774..ba7eea7a2 100644 --- a/PKHeX.Core/PKM/PKMConverter.cs +++ b/PKHeX.Core/PKM/PKMConverter.cs @@ -220,7 +220,7 @@ public static PKM ConvertToType(PKM pk, Type PKMType, out string comment) // Try Incompatible Conversion pkm = GetBlank(PKMType); - TransferProperties(pk, pkm); + pk.TransferPropertiesWithReflection(pkm); if (!SaveUtil.IsPKMCompatibleWithModifications(pkm)) return null; comment = "Converted via reflection."; @@ -455,10 +455,5 @@ public static PKM GetBlank(Type t) var argCount = constructors.First().GetParameters().Length; return (PKM)Activator.CreateInstance(t, new object[argCount]); } - - public static void TransferProperties(PKM source, PKM dest) - { - source.TransferPropertiesWithReflection(source, dest); - } } }