Use min parameter count

PK2 doesn't like getting passed null for the byte[] parameter (rightly
so); don't depend on the src code order having the first constructor
being the one with the least arguments

fix it in pk1/2 so that the first constructor has the least args, anyway
This commit is contained in:
Kurt 2019-03-16 20:04:44 -07:00
parent 8a08d32dff
commit 99baca5f5e
3 changed files with 3 additions and 3 deletions

View file

@ -16,8 +16,8 @@ namespace PKHeX.Core
public override int Format => 1;
public PK1(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { }
public PK1(bool jp = false) : base(new byte[PKX.SIZE_1PARTY], jp) { }
public PK1(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { }
public override PKM Clone() => new PK1((byte[])Data.Clone(), Japanese)
{

View file

@ -15,8 +15,8 @@ namespace PKHeX.Core
public override int Format => 2;
public PK2(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { }
public PK2(bool jp = false) : base(new byte[PKX.SIZE_2PARTY], jp) { }
public PK2(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { }
public override PKM Clone() => new PK2((byte[])Data.Clone(), Japanese)
{

View file

@ -445,7 +445,7 @@ namespace PKHeX.Core
public static PKM GetBlank(Type t)
{
var constructors = t.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic);
var argCount = constructors.First().GetParameters().Length;
var argCount = constructors.Min(z => z.GetParameters().Length);
return (PKM)Activator.CreateInstance(t, new object[argCount]);
}