From 85fba2fb56573ffcd4233faf707dfd7f806b8754 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Fri, 21 Jun 2024 05:18:23 -0400 Subject: [PATCH] Fix some remapper issues --- RecodeItLib/Remapper/ReCodeItRemapper.cs | 17 +++++++++++------ RecodeItLib/Remapper/Search/Fields.cs | 14 ++++++++------ RecodeItLib/Remapper/Search/Methods.cs | 4 ++-- RecodeItLib/Remapper/Search/Properties.cs | 4 ++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/RecodeItLib/Remapper/ReCodeItRemapper.cs b/RecodeItLib/Remapper/ReCodeItRemapper.cs index 96e5185..6402fd0 100644 --- a/RecodeItLib/Remapper/ReCodeItRemapper.cs +++ b/RecodeItLib/Remapper/ReCodeItRemapper.cs @@ -129,6 +129,8 @@ public class ReCodeItRemapper foreach (var nestedType in type.NestedTypes) { + if (remap.SearchParams.IsNested is false) { return; } + FindMatch(nestedType, remap); } @@ -165,7 +167,10 @@ public class ReCodeItRemapper return; } - var match = matches.Where(x => x.Equals(EMatchResult.Match)).Any(); + var match = matches + .Where(x => x.Equals(EMatchResult.Match)) + .Where(x => !x.Equals(EMatchResult.Disabled)) + .Any(); if (match) { @@ -244,7 +249,9 @@ public class ReCodeItRemapper if (scores.Count == 0) { return; } var filteredScores = scores - .OrderByDescending(score => score.Score); + .Where(score => score.Score > 0) + .OrderByDescending(score => score.Score) + .Take(5); var highestScore = filteredScores.FirstOrDefault(); @@ -252,13 +259,11 @@ public class ReCodeItRemapper Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green); - Logger.Log($"Max possible score: {highestScore.ReMap.SearchParams.CalculateMaxScore()}", ConsoleColor.Green); Logger.Log($"Scored: {highestScore.Score} points", ConsoleColor.Green); - if (scores.Count > 1) + if (filteredScores.Count() > 1) { - Logger.Log($"Warning! There were {filteredScores.Count()} possible matches. Considering adding more search parameters", ConsoleColor.Yellow); - Logger.Log($"Only showing first 5.", ConsoleColor.Yellow); + Logger.Log($"Warning! There were {filteredScores.Count()} possible matches. Considering adding more search parameters, Only showing first 5.", ConsoleColor.Yellow); foreach (var score in filteredScores.Skip(1).Take(5)) { diff --git a/RecodeItLib/Remapper/Search/Fields.cs b/RecodeItLib/Remapper/Search/Fields.cs index 090611b..e626c30 100644 --- a/RecodeItLib/Remapper/Search/Fields.cs +++ b/RecodeItLib/Remapper/Search/Fields.cs @@ -19,12 +19,14 @@ internal static class Fields if (parms.IncludeFields is null || parms.IncludeFields.Count == 0) return EMatchResult.Disabled; var matches = type.Fields - .Where(field => parms.IncludeFields.Contains(field.Name)); - score.Score += matches.Count(); + .Where(field => parms.IncludeFields.Contains(field.Name)) + .Count(); - score.FailureReason = matches.Any() ? EFailureReason.None : EFailureReason.FieldsInclude; + score.Score += matches; - return matches.Any() + score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.FieldsInclude; + + return matches > 0 ? EMatchResult.Match : EMatchResult.NoMatch; } @@ -44,9 +46,9 @@ internal static class Fields .Where(field => parms.ExcludeFields.Contains(field.Name)) .Count(); - score.Score += matches; + score.Score -= matches; - score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.FieldsExclude; + score.FailureReason = matches > 0 ? EFailureReason.FieldsExclude : EFailureReason.None; return matches > 0 ? EMatchResult.NoMatch diff --git a/RecodeItLib/Remapper/Search/Methods.cs b/RecodeItLib/Remapper/Search/Methods.cs index 7c6ad65..9a0129d 100644 --- a/RecodeItLib/Remapper/Search/Methods.cs +++ b/RecodeItLib/Remapper/Search/Methods.cs @@ -46,9 +46,9 @@ internal static class Methods .Where(method => parms.ExcludeMethods.Contains(method.Name)) .Count(); - score.Score += matches; + score.Score -= matches; - score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.MethodsExclude; + score.FailureReason = matches > 0 ? EFailureReason.MethodsExclude : EFailureReason.None; return matches > 0 ? EMatchResult.NoMatch diff --git a/RecodeItLib/Remapper/Search/Properties.cs b/RecodeItLib/Remapper/Search/Properties.cs index 8907026..d33bda1 100644 --- a/RecodeItLib/Remapper/Search/Properties.cs +++ b/RecodeItLib/Remapper/Search/Properties.cs @@ -31,9 +31,9 @@ namespace ReCodeIt.ReMapper.Search .Where(property => parms.ExcludeProperties.Contains(property.Name)) .Count(); - score.Score += matches; + score.Score -= matches; - score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.PropertiesExclude; + score.FailureReason = matches > 0 ? EFailureReason.PropertiesExclude : EFailureReason.None; return matches > 0 ? EMatchResult.NoMatch