diff --git a/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs b/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs index 7d67768..09f8baa 100644 --- a/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs +++ b/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs @@ -1,4 +1,5 @@ using Mono.Cecil; +using ReCodeIt.Models; using ReCodeIt.Utils; using ReCodeItLib.Utils; @@ -8,7 +9,7 @@ public class ReCodeItAutoMapper { private List MappingPairs { get; set; } = []; - private List IgnoreNames => DataProvider.Settings.AutoMapper.TypesToIgnore; + private AutoMapperSettings Settings => DataProvider.Settings.AutoMapper; private static readonly List SystemTypeIgnoreList = new() { @@ -68,7 +69,7 @@ public class ReCodeItAutoMapper .Where(f => !f.FieldType.IsValueType) // 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 foreach (var field in fields) @@ -104,7 +105,7 @@ public class ReCodeItAutoMapper .Where(p => !p.PropertyType.IsValueType) // 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 foreach (var property in properties) @@ -117,20 +118,31 @@ public class ReCodeItAutoMapper return propertiesWithTypes; } + /// + /// 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. + /// private void FilterTypeNames() { // Filter types to the ones we're looking for 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 - .Where(pair => !TokensToMatch.Any(token => pair.Name.ToLower().StartsWith(token.ToLower()))); + // Filter out anything that has the same name as the type, we cant remap those + .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) { - 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()}"); } diff --git a/RecodeItLib/Models/AppSettingsModel.cs b/RecodeItLib/Models/AppSettingsModel.cs index 647bc56..89f014c 100644 --- a/RecodeItLib/Models/AppSettingsModel.cs +++ b/RecodeItLib/Models/AppSettingsModel.cs @@ -38,4 +38,6 @@ public class AutoMapperSettings public List TypesToIgnore { get; set; } public List TokensToMatch { get; set; } + + public List PropertyFieldBlackList { get; set; } } \ No newline at end of file diff --git a/Templates/Settings.jsonc b/Templates/Settings.jsonc index 2dd9f5d..4f45899 100644 --- a/Templates/Settings.jsonc +++ b/Templates/Settings.jsonc @@ -15,7 +15,7 @@ }, "AutoMapper": { "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 "Boolean", "List", @@ -36,7 +36,17 @@ "IEnumerator" ], "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", ] } }