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)
This commit is contained in:
Kurt
2018-02-03 15:32:45 -08:00
parent 886398184f
commit 118a213b6c
2 changed files with 8 additions and 11 deletions

View File

@@ -902,16 +902,18 @@ public int GetFlawlessIVCount()
}
/// <summary>
/// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
/// Applies all shared properties from the current <see cref="PKM"/> to <see cref="Destination"/> <see cref="PKM"/>.
/// </summary>
/// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
/// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
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[]))

View File

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