From 4fc850cbb87e6a4435a6218ddd1d8cef9e6f7d25 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:46:46 -0500 Subject: [PATCH] Start of a small project wide refactor to address issues. 28 failing remaps currently. --- Assets/mappings.jsonc | 50 +++++++------- RecodeItLib/Enums/ENoMatchReason.cs | 2 + RecodeItLib/Models/RemapModel.cs | 7 +- RecodeItLib/Remapper/AutoMatcher.cs | 51 ++++++++++---- .../Remapper/Filters/GenericTypeFilters.cs | 46 +------------ .../Remapper/Filters/NestedTypeFilters.cs | 28 ++++++++ RecodeItLib/Remapper/Publicizer.cs | 4 +- RecodeItLib/Remapper/ReMapper.cs | 12 +--- RecodeItLib/Remapper/Renamer.cs | 6 +- RecodeItLib/Remapper/Statistics.cs | 40 ++++++----- RecodeItLib/Remapper/TypeFilters.cs | 66 ++++++++++--------- 11 files changed, 166 insertions(+), 146 deletions(-) diff --git a/Assets/mappings.jsonc b/Assets/mappings.jsonc index 5549a9a..57fe18a 100644 --- a/Assets/mappings.jsonc +++ b/Assets/mappings.jsonc @@ -11075,7 +11075,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": false }, "Methods": { @@ -11116,7 +11116,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true + "IsPublic": false }, "Methods": { "ConstructorParameterCount": -1, @@ -11156,7 +11156,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsAbstract": true }, "Methods": { @@ -11249,7 +11249,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsSealed": true }, "Methods": { @@ -11295,7 +11295,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsAbstract": false }, "Methods": { @@ -11427,7 +11427,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true + "IsPublic": false }, "Methods": { "ConstructorParameterCount": -1, @@ -11516,7 +11516,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsAbstract": true }, "Methods": { @@ -11852,7 +11852,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsSealed": false }, "Methods": { @@ -11899,7 +11899,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsSealed": true }, "Methods": { @@ -12040,7 +12040,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsInterface": true }, "Methods": { @@ -12083,7 +12083,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsInterface": true }, "Methods": { @@ -12127,7 +12127,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsInterface": true }, "Methods": { @@ -13234,7 +13234,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsAbstract": false, "IsInterface": false, "IsStruct": false, @@ -14982,7 +14982,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsAbstract": true }, "Methods": { @@ -15251,7 +15251,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsInterface": true }, "Methods": { @@ -15298,7 +15298,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -15347,7 +15347,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -15397,7 +15397,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -15448,7 +15448,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -16790,7 +16790,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsStruct": true }, "Methods": { @@ -16837,7 +16837,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsStruct": true }, "Methods": { @@ -16926,7 +16926,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -16976,7 +16976,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -17023,7 +17023,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true, + "IsPublic": false, "IsDerived": true }, "Methods": { @@ -17245,7 +17245,7 @@ "UseForceRename": false, "SearchParams": { "GenericParams": { - "IsPublic": true + "IsPublic": false }, "Methods": { "ConstructorParameterCount": -1, diff --git a/RecodeItLib/Enums/ENoMatchReason.cs b/RecodeItLib/Enums/ENoMatchReason.cs index 2911219..cac43e2 100644 --- a/RecodeItLib/Enums/ENoMatchReason.cs +++ b/RecodeItLib/Enums/ENoMatchReason.cs @@ -5,6 +5,7 @@ public enum ENoMatchReason AmbiguousWithPreviousMatch, AmbiguousNewTypeNames, IsPublic, + IsAbstract, IsEnum, IsNested, IsSealed, @@ -26,6 +27,7 @@ public enum ENoMatchReason NestedTypeInclude, NestedTypeExclude, NestedTypeCount, + NestedVisibility, EventsInclude, EventsExclude } \ No newline at end of file diff --git a/RecodeItLib/Models/RemapModel.cs b/RecodeItLib/Models/RemapModel.cs index 95b00c1..833c424 100644 --- a/RecodeItLib/Models/RemapModel.cs +++ b/RecodeItLib/Models/RemapModel.cs @@ -56,7 +56,6 @@ public class SearchParams public class GenericParams { public bool IsPublic { get; set; } = true; - public bool? IsAbstract { get; set; } = null; public bool? IsInterface { get; set; } = null; public bool? IsStruct { get; set; } = null; @@ -97,6 +96,12 @@ public class PropertyParams public class NestedTypeParams { public bool IsNested { get; set; } + public bool IsNestedAssembly { get; set; } + public bool IsNestedFamily { get; set; } + public bool IsNestedPrivate { get; set; } + public bool IsNestedPublic { get; set; } + public bool IsNestedFamilyAndAssembly { get; set; } + public bool IsNestedFamilyOrAssembly { get; set; } /// /// Name of the nested types parent diff --git a/RecodeItLib/Remapper/AutoMatcher.cs b/RecodeItLib/Remapper/AutoMatcher.cs index b5ec8a4..df2b662 100644 --- a/RecodeItLib/Remapper/AutoMatcher.cs +++ b/RecodeItLib/Remapper/AutoMatcher.cs @@ -22,12 +22,9 @@ public class AutoMatcher(List mappings, string mappingPath) out var module); Module = module; - CandidateTypes = Module.GetTypes() - .Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token))) - .ToList(); var targetTypeDef = FindTargetType(oldTypeName); - + if (targetTypeDef is null) { Logger.LogSync($"Could not target type: {oldTypeName}", ConsoleColor.Red); @@ -36,9 +33,24 @@ public class AutoMatcher(List mappings, string mappingPath) Logger.LogSync($"Found target type: {targetTypeDef!.FullName}", ConsoleColor.Green); - var remapModel = new RemapModel(); - remapModel.NewTypeName = newTypeName; - remapModel.AutoGenerated = true; + if (targetTypeDef.IsNested) + { + CandidateTypes = targetTypeDef.DeclaringType.NestedTypes + .Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token))) + .ToList(); + } + else + { + CandidateTypes = Module.Types + .Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token))) + .ToList(); + } + + var remapModel = new RemapModel() + { + NewTypeName = newTypeName, + AutoGenerated = true + }; StartFilter(targetTypeDef, remapModel, assemblyPath); } @@ -57,36 +69,42 @@ public class AutoMatcher(List mappings, string mappingPath) { if (!PassesGeneralChecks(target, candidate, remapModel.SearchParams.GenericParams)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after general checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); continue; } if (!ContainsTargetMethods(target, candidate, remapModel.SearchParams.Methods)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after method checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); continue; } if (!ContainsTargetFields(target, candidate, remapModel.SearchParams.Fields)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after field checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); continue; } if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after property checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); continue; } if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after nested checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); continue; } if (!ContainsTargetEvents(target, candidate, remapModel.SearchParams.Events)) { + Logger.LogSync($"Candidate: {candidate.Name} filtered out after event checks", ConsoleColor.Yellow); CandidateTypes!.Remove(candidate); } } @@ -102,8 +120,10 @@ public class AutoMatcher(List mappings, string mappingPath) new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true); - ProcessEndQuestions(remapModel, assemblyPath); - return; + if (remapModel.Succeeded) + { + ProcessEndQuestions(remapModel, assemblyPath); + } } Logger.LogSync("Could not find a match... :(", ConsoleColor.Red); @@ -183,7 +203,8 @@ public class AutoMatcher(List mappings, string mappingPath) methods.ConstructorParameterCount = target.Methods.First(m => m.IsConstructor && m.Parameters.Count > 0).Parameters.Count - 1; } - return commonMethods.Any(); + // True if we have common methods, or all methods are constructors + return commonMethods.Any() || target.Methods.All(m => m.IsConstructor); } private bool ContainsTargetFields(TypeDef target, TypeDef candidate, FieldParams fields) @@ -294,13 +315,19 @@ public class AutoMatcher(List mappings, string mappingPath) nt.NestedTypeCount = target.NestedTypes.Count; nt.IsNested = target.IsNested; - + nt.IsNestedAssembly = target.IsNestedAssembly; + nt.IsNestedFamily = target.IsNestedFamily; + nt.IsNestedPrivate = target.IsNestedPrivate; + nt.IsNestedPublic = target.IsNestedPublic; + nt.IsNestedFamilyAndAssembly = target.IsNestedFamilyAndAssembly; + nt.IsNestedFamilyOrAssembly = target.IsNestedFamilyOrAssembly; + if (target.DeclaringType is not null) { nt.NestedTypeParentName = target.DeclaringType.Name.String; } - return commonNts.Any() || !target.IsNested; + return commonNts.Any() || target.NestedTypes.Count == 0; } private bool ContainsTargetEvents(TypeDef target, TypeDef candidate, EventParams events) diff --git a/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs index 7d76c92..24ca7a0 100644 --- a/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/GenericTypeFilters.cs @@ -1,5 +1,6 @@ using dnlib.DotNet; using ReCodeItLib.Models; +using ReCodeItLib.Utils; namespace ReCodeItLib.ReMapper.Filters; @@ -14,50 +15,9 @@ internal static class GenericTypeFilters /// Filtered list public static IEnumerable FilterPublic(IEnumerable types, SearchParams parms) { - // REQUIRED PROPERTY - if (parms.GenericParams.IsPublic) - { - if (parms.NestedTypes.IsNested is true) - { - types = types.Where(t => t.IsNestedPublic); - - types = FilterNestedByName(types, parms); - } - else - { - types = types.Where(t => t.IsPublic); - } - } - else - { - if (parms.NestedTypes.IsNested is true) - { - types = types.Where(t => t.IsNestedPrivate - || t.IsNestedFamily - || t.IsNestedFamilyAndAssembly - || t.IsNestedAssembly); - - types = FilterNestedByName(types, parms); - } - else - { - types = types.Where(t => t.IsNotPublic); - } - } - - return types; + return types.Where(t => t.IsPublic == parms.GenericParams.IsPublic); } - - private static IEnumerable FilterNestedByName(IEnumerable types, SearchParams parms) - { - if (parms.NestedTypes.NestedTypeParentName is not "") - { - types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName); - } - - return types; - } - + /// /// Filters based on IsAbstract /// diff --git a/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs b/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs index 743e417..e4a2e25 100644 --- a/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs +++ b/RecodeItLib/Remapper/Filters/NestedTypeFilters.cs @@ -71,4 +71,32 @@ internal static class NestedTypeFilters return types; } + + public static IEnumerable FilterByNestedVisibility(IEnumerable types, SearchParams parms) + { + types = FilterNestedByName(types, parms); + + var ntp = parms.NestedTypes; + + types = types.Where(t => + t.IsNestedAssembly == ntp.IsNestedAssembly + && t.IsNestedFamily == ntp.IsNestedFamily + && t.IsNestedPrivate == ntp.IsNestedPrivate + && t.IsNestedPublic == ntp.IsNestedPublic + && t.IsNestedFamilyAndAssembly == ntp.IsNestedFamilyAndAssembly + && t.IsNestedFamilyOrAssembly == ntp.IsNestedFamilyOrAssembly + ); + + return types; + } + + private static IEnumerable FilterNestedByName(IEnumerable types, SearchParams parms) + { + if (parms.NestedTypes.NestedTypeParentName is not "") + { + types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName); + } + + return types; + } } \ No newline at end of file diff --git a/RecodeItLib/Remapper/Publicizer.cs b/RecodeItLib/Remapper/Publicizer.cs index 5f8f0ac..8f67be2 100644 --- a/RecodeItLib/Remapper/Publicizer.cs +++ b/RecodeItLib/Remapper/Publicizer.cs @@ -9,7 +9,7 @@ internal class Publicizer { var types = definition.GetTypes(); - var publicizeTasks = new List(); + var publicizeTasks = new List(types.Count(t => !t.IsNested)); foreach (var type in types) { if (type.IsNested) continue; // Nested types are handled when publicizing the parent type @@ -25,7 +25,7 @@ internal class Publicizer // TODO: This is broken. No idea why. while (!publicizeTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) { - Logger.DrawProgressBar(publicizeTasks.Where(t => t.IsCompleted)!.Count() + 1, publicizeTasks.Count, 50); + Logger.DrawProgressBar(publicizeTasks.Count(t => t.IsCompleted), publicizeTasks.Count, 50); } Task.WaitAll(publicizeTasks.ToArray()); diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 8edbe82..89682b0 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -173,15 +173,9 @@ public class ReMapper } // Filter down nested objects - if (mapping.SearchParams.NestedTypes.IsNested is false) - { - types = types.Where(type => tokens!.Any(token => type.Name.StartsWith(token))); - } - - if (mapping.SearchParams.NestedTypes.NestedTypeParentName != string.Empty) - { - types = types.Where(t => t.DeclaringType != null && t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName); - } + types = !mapping.SearchParams.NestedTypes.IsNested + ? types.Where(type => tokens!.Any(token => type.Name.StartsWith(token))) + : types.Where(t => t.DeclaringType != null && t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName); // Run through a series of filters and report an error if all types are filtered out. var filters = new TypeFilters(); diff --git a/RecodeItLib/Remapper/Renamer.cs b/RecodeItLib/Remapper/Renamer.cs index 07f18db..e335f93 100644 --- a/RecodeItLib/Remapper/Renamer.cs +++ b/RecodeItLib/Remapper/Renamer.cs @@ -16,11 +16,7 @@ internal class Renamer /// public void RenameAll(IEnumerable types, RemapModel remap) { - if (remap.TypePrimeCandidate is null) - { - Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red); - return; - } + if (remap.TypePrimeCandidate is null) return; // Rename all fields and properties first RenameAllFields( diff --git a/RecodeItLib/Remapper/Statistics.cs b/RecodeItLib/Remapper/Statistics.cs index e2ad56e..87b923c 100644 --- a/RecodeItLib/Remapper/Statistics.cs +++ b/RecodeItLib/Remapper/Statistics.cs @@ -53,27 +53,31 @@ public class Statistics( foreach (var remap in remapModels) { - if (remap.Succeeded is false && remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch)) + switch (remap.Succeeded) { - Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); - Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red); - Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red); - Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red); - Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); - } - else if (remap.Succeeded is false) - { - Logger.Log("-----------------------------------------------", ConsoleColor.Red); - Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red); - - foreach (var reason in remap.NoMatchReasons) + case false when remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch): + Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); + Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red); + Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red); + Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red); + Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); + + failures++; + break; + case false: { - Logger.Log($"Reason: {reason}", ConsoleColor.Red); - } + Logger.Log("-----------------------------------------------", ConsoleColor.Red); + Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red); - Logger.Log("-----------------------------------------------", ConsoleColor.Red); - failures++; - continue; + foreach (var reason in remap.NoMatchReasons) + { + Logger.Log($"Reason: {reason}", ConsoleColor.Red); + } + + Logger.Log("-----------------------------------------------", ConsoleColor.Red); + failures++; + continue; + } } if (validate && remap.Succeeded) diff --git a/RecodeItLib/Remapper/TypeFilters.cs b/RecodeItLib/Remapper/TypeFilters.cs index 4e4e558..464d9a5 100644 --- a/RecodeItLib/Remapper/TypeFilters.cs +++ b/RecodeItLib/Remapper/TypeFilters.cs @@ -26,7 +26,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); + AddNoMatchReason(mapping, ENoMatchReason.IsPublic); mapping.TypeCandidates.UnionWith(types); return false; } @@ -35,7 +35,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); + AddNoMatchReason(mapping, ENoMatchReason.IsAbstract); mapping.TypeCandidates.UnionWith(types); return false; } @@ -44,7 +44,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsSealed); + AddNoMatchReason(mapping, ENoMatchReason.IsSealed); mapping.TypeCandidates.UnionWith(types); return false; } @@ -53,7 +53,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsInterface); + AddNoMatchReason(mapping, ENoMatchReason.IsInterface); mapping.TypeCandidates.UnionWith(types); return false; } @@ -62,7 +62,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsStruct); + AddNoMatchReason(mapping, ENoMatchReason.IsStruct); mapping.TypeCandidates.UnionWith(types); return false; } @@ -71,7 +71,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsEnum); + AddNoMatchReason(mapping, ENoMatchReason.IsEnum); mapping.TypeCandidates.UnionWith(types); return false; } @@ -80,7 +80,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.HasAttribute); + AddNoMatchReason(mapping, ENoMatchReason.HasAttribute); mapping.TypeCandidates.UnionWith(types); return false; } @@ -89,7 +89,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.IsDerived); + AddNoMatchReason(mapping, ENoMatchReason.IsDerived); mapping.TypeCandidates.UnionWith(types); return false; } @@ -98,7 +98,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.HasGenericParameters); + AddNoMatchReason(mapping, ENoMatchReason.HasGenericParameters); mapping.TypeCandidates.UnionWith(types); return false; } @@ -112,7 +112,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsInclude); + AddNoMatchReason(mapping, ENoMatchReason.MethodsInclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -121,7 +121,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsExclude); + AddNoMatchReason(mapping, ENoMatchReason.MethodsExclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -130,7 +130,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsCount); + AddNoMatchReason(mapping, ENoMatchReason.MethodsCount); mapping.TypeCandidates.UnionWith(types); return false; } @@ -139,7 +139,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.ConstructorParameterCount); + AddNoMatchReason(mapping, ENoMatchReason.ConstructorParameterCount); mapping.TypeCandidates.UnionWith(types); return false; } @@ -153,7 +153,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsInclude); + AddNoMatchReason(mapping, ENoMatchReason.FieldsInclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -162,7 +162,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsExclude); + AddNoMatchReason(mapping, ENoMatchReason.FieldsExclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -171,7 +171,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsCount); + AddNoMatchReason(mapping, ENoMatchReason.FieldsCount); mapping.TypeCandidates.UnionWith(types); return false; } @@ -185,7 +185,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude); + AddNoMatchReason(mapping, ENoMatchReason.PropertiesInclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -194,7 +194,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude); + AddNoMatchReason(mapping, ENoMatchReason.PropertiesExclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -203,7 +203,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesCount); + AddNoMatchReason(mapping, ENoMatchReason.PropertiesCount); mapping.TypeCandidates.UnionWith(types); return false; } @@ -217,7 +217,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeInclude); + AddNoMatchReason(mapping, ENoMatchReason.NestedTypeInclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -226,7 +226,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeExclude); + AddNoMatchReason(mapping, ENoMatchReason.NestedTypeExclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -235,7 +235,16 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeCount); + AddNoMatchReason(mapping, ENoMatchReason.NestedTypeCount); + mapping.TypeCandidates.UnionWith(types); + return false; + } + + types = NestedTypeFilters.FilterByNestedVisibility(types, mapping.SearchParams); + + if (!types.Any()) + { + AddNoMatchReason(mapping, ENoMatchReason.NestedVisibility); mapping.TypeCandidates.UnionWith(types); return false; } @@ -249,7 +258,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsInclude); + AddNoMatchReason(mapping, ENoMatchReason.EventsInclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -258,7 +267,7 @@ public class TypeFilters if (!types.Any()) { - AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsExclude); + AddNoMatchReason(mapping, ENoMatchReason.EventsExclude); mapping.TypeCandidates.UnionWith(types); return false; } @@ -266,13 +275,8 @@ public class TypeFilters return true; } - /// - /// This is used to log that all types for a given remap were filtered out. - /// - /// remap model that failed - /// Reason for filtering - private static void AllTypesFilteredOutFor(RemapModel remap, ENoMatchReason noMatchReason) + private static void AddNoMatchReason(RemapModel remap, ENoMatchReason noMatchReason) { - Logger.Log($"All types filtered out after `{noMatchReason}` filter for: `{remap.NewTypeName}`", ConsoleColor.Red); + remap.NoMatchReasons.Add(noMatchReason); } } \ No newline at end of file