From eb8dc1033011a6970b0826838d38f78a87c56c64 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:11:06 -0400 Subject: [PATCH] Small adjustment to scoring --- RecodeItLib/Remapper/ReCodeItRemapper.cs | 7 +++++++ RecodeItLib/Remapper/Search/Fields.cs | 6 +++--- RecodeItLib/Remapper/Search/Methods.cs | 6 +++--- RecodeItLib/Remapper/Search/NestedTypes.cs | 9 +++++---- RecodeItLib/Remapper/Search/Properties.cs | 9 ++++----- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/RecodeItLib/Remapper/ReCodeItRemapper.cs b/RecodeItLib/Remapper/ReCodeItRemapper.cs index 88ee340..48b146b 100644 --- a/RecodeItLib/Remapper/ReCodeItRemapper.cs +++ b/RecodeItLib/Remapper/ReCodeItRemapper.cs @@ -127,6 +127,13 @@ public class ReCodeItRemapper return; } + var tokens = DataProvider.Settings.AutoMapper.TokensToMatch; + + if (tokens.Where(token => !tokens.Any(token => type.Name.StartsWith(token))).Any()) + { + return; + } + foreach (var nestedType in type.NestedTypes) { if (remap.SearchParams.IsNested is false) { return; } diff --git a/RecodeItLib/Remapper/Search/Fields.cs b/RecodeItLib/Remapper/Search/Fields.cs index e626c30..a4122a2 100644 --- a/RecodeItLib/Remapper/Search/Fields.cs +++ b/RecodeItLib/Remapper/Search/Fields.cs @@ -22,7 +22,7 @@ internal static class Fields .Where(field => parms.IncludeFields.Contains(field.Name)) .Count(); - score.Score += matches; + score.Score += matches > 0 ? matches : -matches; score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.FieldsInclude; @@ -46,7 +46,7 @@ internal static class Fields .Where(field => parms.ExcludeFields.Contains(field.Name)) .Count(); - score.Score -= matches; + score.Score += matches > 0 ? -matches : 1; score.FailureReason = matches > 0 ? EFailureReason.FieldsExclude : EFailureReason.None; @@ -68,7 +68,7 @@ internal static class Fields var match = type.Fields.Exactly((int)parms.FieldCount); - if (match) { score.Score++; } + score.Score += match ? (int)parms.FieldCount : -(int)parms.FieldCount; score.FailureReason = match ? EFailureReason.None : EFailureReason.FieldsCount; diff --git a/RecodeItLib/Remapper/Search/Methods.cs b/RecodeItLib/Remapper/Search/Methods.cs index 9a0129d..a49d483 100644 --- a/RecodeItLib/Remapper/Search/Methods.cs +++ b/RecodeItLib/Remapper/Search/Methods.cs @@ -22,7 +22,7 @@ internal static class Methods .Where(method => parms.IncludeMethods.Any(include => method.Name.Contains(include))) .Count(); - score.Score += matches; + score.Score += matches > 0 ? matches : -matches; score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.MethodsInclude; @@ -46,7 +46,7 @@ internal static class Methods .Where(method => parms.ExcludeMethods.Contains(method.Name)) .Count(); - score.Score -= matches; + score.Score += matches > 0 ? -matches : 1; score.FailureReason = matches > 0 ? EFailureReason.MethodsExclude : EFailureReason.None; @@ -69,7 +69,7 @@ internal static class Methods var numMethods = type.Methods.Count - type.GetConstructors().Count(); bool match = numMethods == parms.MethodCount; - if (match) { score.Score++; } + score.Score += match ? (int)parms.MethodCount : -(int)parms.MethodCount; score.FailureReason = match ? EFailureReason.None : EFailureReason.MethodsCount; diff --git a/RecodeItLib/Remapper/Search/NestedTypes.cs b/RecodeItLib/Remapper/Search/NestedTypes.cs index a9c456c..3d19ea8 100644 --- a/RecodeItLib/Remapper/Search/NestedTypes.cs +++ b/RecodeItLib/Remapper/Search/NestedTypes.cs @@ -14,7 +14,8 @@ internal class NestedTypes var matches = type.NestedTypes .Where(nt => parms.IncludeNestedTypes.Contains(nt.Name)) .Count(); - score.Score += matches; + + score.Score += matches > 0 ? matches : -matches; score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.NestedTypeInclude; @@ -31,9 +32,9 @@ internal class NestedTypes .Where(nt => parms.ExcludeNestedTypes.Contains(nt.Name)) .Count(); - score.Score += matches; + score.Score += matches > 0 ? -matches : 1; - score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.NestedTypeExclude; + score.FailureReason = matches > 0 ? EFailureReason.NestedTypeExclude : EFailureReason.None; return matches > 0 ? EMatchResult.NoMatch @@ -46,7 +47,7 @@ internal class NestedTypes var match = type.NestedTypes.Exactly((int)parms.NestedTypeCount); - if (match) { score.Score++; } + score.Score += match ? type.NestedTypes.Count : -type.NestedTypes.Count - 1; score.FailureReason = match ? EFailureReason.None : EFailureReason.NestedTypeCount; diff --git a/RecodeItLib/Remapper/Search/Properties.cs b/RecodeItLib/Remapper/Search/Properties.cs index d33bda1..3b2e266 100644 --- a/RecodeItLib/Remapper/Search/Properties.cs +++ b/RecodeItLib/Remapper/Search/Properties.cs @@ -14,7 +14,8 @@ namespace ReCodeIt.ReMapper.Search var matches = type.Properties .Where(property => parms.IncludeProperties.Contains(property.Name)) .Count(); - score.Score += matches; + + score.Score += matches > 0 ? matches : -matches; score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.PropertiesInclude; @@ -31,7 +32,7 @@ namespace ReCodeIt.ReMapper.Search .Where(property => parms.ExcludeProperties.Contains(property.Name)) .Count(); - score.Score -= matches; + score.Score += matches > 0 ? -matches : 1; score.FailureReason = matches > 0 ? EFailureReason.PropertiesExclude : EFailureReason.None; @@ -46,9 +47,7 @@ namespace ReCodeIt.ReMapper.Search var match = type.Properties.Exactly((int)parms.PropertyCount); - if (match) { score.Score++; } - - score.FailureReason = match ? EFailureReason.None : EFailureReason.PropertiesCount; + score.Score += match ? (int)parms.PropertyCount : -(int)parms.PropertyCount; return match ? EMatchResult.Match