Small adjustment to scoring

This commit is contained in:
Cj 2024-06-21 14:11:06 -04:00
parent 58450e6bc3
commit eb8dc10330
5 changed files with 22 additions and 15 deletions

View File

@ -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; }

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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