From dcfeff7bf3c1d9cf9a253396a138ae95461fac43 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 13 Jun 2018 18:52:09 -0700 Subject: [PATCH] Update batch editing Permit all possible properties in the dropdown, handle can't write cases (many) as well as can't read (I don't think there are any of these). https://projectpokemon.org/home/forums/topic/45789-how-to-require-a-pkm-equals-a-shiny-pid-in-batch-editor/?do=findComment&comment=232757 --- PKHeX.Core/Editing/Bulk/BatchEditing.cs | 17 ++++++++++++----- PKHeX.Core/Util/ReflectUtil.cs | 11 +++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/PKHeX.Core/Editing/Bulk/BatchEditing.cs b/PKHeX.Core/Editing/Bulk/BatchEditing.cs index 9c4e1cf57..f7ddd09e5 100644 --- a/PKHeX.Core/Editing/Bulk/BatchEditing.cs +++ b/PKHeX.Core/Editing/Bulk/BatchEditing.cs @@ -21,7 +21,7 @@ public static class BatchEditing public static readonly string[] CustomProperties = { PROP_LEGAL }; public static readonly string[][] Properties = GetPropArray(); - private static readonly Dictionary[] Props = Types.Select(z => ReflectUtil.GetAllPropertyInfoCanWritePublic(z) + private static readonly Dictionary[] Props = Types.Select(z => ReflectUtil.GetAllPropertyInfoPublic(z) .GroupBy(p => p.Name).Select(g => g.First()).ToDictionary(p => p.Name)) .ToArray(); @@ -38,12 +38,12 @@ private static string[][] GetPropArray() var p = new string[Types.Length][]; for (int i = 0; i < p.Length; i++) { - var pz = ReflectUtil.GetPropertiesCanWritePublic(Types[i]); + var pz = ReflectUtil.GetPropertiesPublic(Types[i]); p[i] = pz.Concat(CustomProperties).OrderBy(a => a).ToArray(); } // Properties for any PKM - var any = ReflectUtil.GetPropertiesCanWritePublic(typeof(PK1)).Union(p.SelectMany(a => a)).OrderBy(a => a).ToArray(); + var any = ReflectUtil.GetPropertiesPublic(typeof(PK1)).Union(p.SelectMany(a => a)).OrderBy(a => a).ToArray(); // Properties shared by all PKM var all = p.Aggregate(new HashSet(p[0]), (h, e) => { h.IntersectWith(e); return h; }).OrderBy(a => a).ToArray(); @@ -87,7 +87,7 @@ public static string GetPropertyType(string propertyName, int typeIndex = 0) return null; } - int index = typeIndex == Props.Length - 1 ? 0 : typeIndex - 1; // All vs Specific + int index = typeIndex -1 >= Props.Length ? 0 : typeIndex - 1; // All vs Specific var pr = Props[index]; if (!pr.TryGetValue(propertyName, out var info)) return null; @@ -209,7 +209,7 @@ internal static ModifyResult TryModifyPKM(PKM pkm, IEnumerable GetAllPropertyInfoCanWritePublic(Type ty return type.GetTypeInfo().GetAllTypeInfo().SelectMany(GetAllProperties) .Where(p => p.CanWrite && p.SetMethod.IsPublic); } + public static IEnumerable GetAllPropertyInfoPublic(Type type) + { + return type.GetTypeInfo().GetAllTypeInfo().SelectMany(GetAllProperties) + .Where(p => (p.CanRead && p.GetMethod.IsPublic) || (p.CanWrite && p.SetMethod.IsPublic)); + } + public static IEnumerable GetPropertiesPublic(Type type) + { + return GetAllPropertyInfoPublic(type).Select(p => p.Name) + .Distinct() + ; + } public static IEnumerable GetPropertiesCanWritePublicDeclared(Type type) {