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); - } } }