More filtering
This commit is contained in:
parent
5a3df6593b
commit
75f2c16d80
@ -1,4 +1,5 @@
|
|||||||
using Mono.Cecil;
|
using Mono.Cecil;
|
||||||
|
using ReCodeIt.Models;
|
||||||
using ReCodeIt.Utils;
|
using ReCodeIt.Utils;
|
||||||
using ReCodeItLib.Utils;
|
using ReCodeItLib.Utils;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ public class ReCodeItAutoMapper
|
|||||||
{
|
{
|
||||||
private List<MappingPair> MappingPairs { get; set; } = [];
|
private List<MappingPair> MappingPairs { get; set; } = [];
|
||||||
|
|
||||||
private List<string> IgnoreNames => DataProvider.Settings.AutoMapper.TypesToIgnore;
|
private AutoMapperSettings Settings => DataProvider.Settings.AutoMapper;
|
||||||
|
|
||||||
private static readonly List<string> SystemTypeIgnoreList = new()
|
private static readonly List<string> SystemTypeIgnoreList = new()
|
||||||
{
|
{
|
||||||
@ -68,7 +69,7 @@ public class ReCodeItAutoMapper
|
|||||||
.Where(f => !f.FieldType.IsValueType)
|
.Where(f => !f.FieldType.IsValueType)
|
||||||
|
|
||||||
// We dont want fields in the system type ignore list
|
// We dont want fields in the system type ignore list
|
||||||
.Where(f => !IgnoreNames.Contains(f.FieldType.Name.TrimAfterSpecialChar()));
|
.Where(f => !Settings.TypesToIgnore.Contains(f.FieldType.Name.TrimAfterSpecialChar()));
|
||||||
|
|
||||||
// Include fields from the current type
|
// Include fields from the current type
|
||||||
foreach (var field in fields)
|
foreach (var field in fields)
|
||||||
@ -104,7 +105,7 @@ public class ReCodeItAutoMapper
|
|||||||
.Where(p => !p.PropertyType.IsValueType)
|
.Where(p => !p.PropertyType.IsValueType)
|
||||||
|
|
||||||
// We dont want fields in the global ignore list
|
// We dont want fields in the global ignore list
|
||||||
.Where(p => !IgnoreNames.Contains(p.PropertyType.Name.TrimAfterSpecialChar()));
|
.Where(p => !Settings.TypesToIgnore.Contains(p.PropertyType.Name.TrimAfterSpecialChar()));
|
||||||
|
|
||||||
// Include fields from the current type
|
// Include fields from the current type
|
||||||
foreach (var property in properties)
|
foreach (var property in properties)
|
||||||
@ -117,20 +118,31 @@ public class ReCodeItAutoMapper
|
|||||||
return propertiesWithTypes;
|
return propertiesWithTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filters down match pairs to match deobfuscating names 'ClassXXXX' to field or property names
|
||||||
|
/// that are not of the same value, also applies a length filter.
|
||||||
|
/// </summary>
|
||||||
private void FilterTypeNames()
|
private void FilterTypeNames()
|
||||||
{
|
{
|
||||||
// Filter types to the ones we're looking for
|
// Filter types to the ones we're looking for
|
||||||
var mappingPairs = MappingPairs
|
var mappingPairs = MappingPairs
|
||||||
.Where(pair => TokensToMatch.Any(token => pair.Type.Name.StartsWith(token)))
|
.Where(pair => Settings.TokensToMatch.Any(token => pair.Type.Name.StartsWith(token)))
|
||||||
|
|
||||||
// Filter out anything that has the same name as the type
|
// Filter out anything that has the same name as the type, we cant remap those
|
||||||
.Where(pair => !TokensToMatch.Any(token => pair.Name.ToLower().StartsWith(token.ToLower())));
|
.Where(pair => !Settings.TokensToMatch.Any(token => pair.Name.ToLower().StartsWith(token.ToLower())))
|
||||||
|
|
||||||
|
// Filter based on length, short lengths dont make good class names
|
||||||
|
.Where(pair => pair.Name.Length >= Settings.MinLengthToMatch)
|
||||||
|
|
||||||
|
// Filter based on direct name blacklist
|
||||||
|
.Where(pair => !Settings.PropertyFieldBlackList.Any(token => pair.Name.ToLower().StartsWith(token.ToLower())));
|
||||||
|
|
||||||
foreach (var pair in mappingPairs)
|
foreach (var pair in mappingPairs)
|
||||||
{
|
{
|
||||||
Logger.Log($"Type: {pair.Type.Name} identifier: {pair.Name}");
|
Logger.Log($"Type: {pair.Type.FullName} identifier: {pair.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MappingPairs = mappingPairs.ToList();
|
||||||
Logger.Log($"Match Count {mappingPairs.Count()}");
|
Logger.Log($"Match Count {mappingPairs.Count()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,4 +38,6 @@ public class AutoMapperSettings
|
|||||||
public List<string> TypesToIgnore { get; set; }
|
public List<string> TypesToIgnore { get; set; }
|
||||||
|
|
||||||
public List<string> TokensToMatch { get; set; }
|
public List<string> TokensToMatch { get; set; }
|
||||||
|
|
||||||
|
public List<string> PropertyFieldBlackList { get; set; }
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"AutoMapper": {
|
"AutoMapper": {
|
||||||
"RequiredMatches": 5, // Minimum number of times a member must have this name in the assembly before considering it for remapping
|
"RequiredMatches": 5, // Minimum number of times a member must have this name in the assembly before considering it for remapping
|
||||||
"MinLengthToMatch": 6, // Minimum length of the field/property name in code before it will be considered for a rename
|
"MinLengthToMatch": 7, // Minimum length of the field/property name in code before it will be considered for a rename
|
||||||
"TypesToIgnore": [ // Any member name you want to ignore while iterating through the assembly
|
"TypesToIgnore": [ // Any member name you want to ignore while iterating through the assembly
|
||||||
"Boolean",
|
"Boolean",
|
||||||
"List",
|
"List",
|
||||||
@ -36,7 +36,17 @@
|
|||||||
"IEnumerator"
|
"IEnumerator"
|
||||||
],
|
],
|
||||||
"TokensToMatch": [ // The auto mapper will look for these tokens in class names and prioritize those
|
"TokensToMatch": [ // The auto mapper will look for these tokens in class names and prioritize those
|
||||||
|
"Class",
|
||||||
|
"GClass"
|
||||||
|
],
|
||||||
|
"PropertyFieldBlackList": [ // Property or fields names to ignore in the automap, these are case sanitized so case does not matter
|
||||||
|
"Columns",
|
||||||
|
"mColumns",
|
||||||
|
"Template",
|
||||||
|
"Condition",
|
||||||
|
"Conditions",
|
||||||
|
"counter",
|
||||||
|
"Instance",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user