0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-13 00:50:45 -05:00

Start of a small project wide refactor to address issues. 28 failing remaps currently.

This commit is contained in:
Cj 2025-01-09 11:46:46 -05:00
parent 7c54b8542c
commit 4fc850cbb8
11 changed files with 166 additions and 146 deletions

View File

@ -11075,7 +11075,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": false "IsDerived": false
}, },
"Methods": { "Methods": {
@ -11116,7 +11116,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true "IsPublic": false
}, },
"Methods": { "Methods": {
"ConstructorParameterCount": -1, "ConstructorParameterCount": -1,
@ -11156,7 +11156,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsAbstract": true "IsAbstract": true
}, },
"Methods": { "Methods": {
@ -11249,7 +11249,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsSealed": true "IsSealed": true
}, },
"Methods": { "Methods": {
@ -11295,7 +11295,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsAbstract": false "IsAbstract": false
}, },
"Methods": { "Methods": {
@ -11427,7 +11427,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true "IsPublic": false
}, },
"Methods": { "Methods": {
"ConstructorParameterCount": -1, "ConstructorParameterCount": -1,
@ -11516,7 +11516,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsAbstract": true "IsAbstract": true
}, },
"Methods": { "Methods": {
@ -11852,7 +11852,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsSealed": false "IsSealed": false
}, },
"Methods": { "Methods": {
@ -11899,7 +11899,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsSealed": true "IsSealed": true
}, },
"Methods": { "Methods": {
@ -12040,7 +12040,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsInterface": true "IsInterface": true
}, },
"Methods": { "Methods": {
@ -12083,7 +12083,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsInterface": true "IsInterface": true
}, },
"Methods": { "Methods": {
@ -12127,7 +12127,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsInterface": true "IsInterface": true
}, },
"Methods": { "Methods": {
@ -13234,7 +13234,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsAbstract": false, "IsAbstract": false,
"IsInterface": false, "IsInterface": false,
"IsStruct": false, "IsStruct": false,
@ -14982,7 +14982,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsAbstract": true "IsAbstract": true
}, },
"Methods": { "Methods": {
@ -15251,7 +15251,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsInterface": true "IsInterface": true
}, },
"Methods": { "Methods": {
@ -15298,7 +15298,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -15347,7 +15347,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -15397,7 +15397,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -15448,7 +15448,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -16790,7 +16790,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsStruct": true "IsStruct": true
}, },
"Methods": { "Methods": {
@ -16837,7 +16837,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsStruct": true "IsStruct": true
}, },
"Methods": { "Methods": {
@ -16926,7 +16926,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -16976,7 +16976,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -17023,7 +17023,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true, "IsPublic": false,
"IsDerived": true "IsDerived": true
}, },
"Methods": { "Methods": {
@ -17245,7 +17245,7 @@
"UseForceRename": false, "UseForceRename": false,
"SearchParams": { "SearchParams": {
"GenericParams": { "GenericParams": {
"IsPublic": true "IsPublic": false
}, },
"Methods": { "Methods": {
"ConstructorParameterCount": -1, "ConstructorParameterCount": -1,

View File

@ -5,6 +5,7 @@ public enum ENoMatchReason
AmbiguousWithPreviousMatch, AmbiguousWithPreviousMatch,
AmbiguousNewTypeNames, AmbiguousNewTypeNames,
IsPublic, IsPublic,
IsAbstract,
IsEnum, IsEnum,
IsNested, IsNested,
IsSealed, IsSealed,
@ -26,6 +27,7 @@ public enum ENoMatchReason
NestedTypeInclude, NestedTypeInclude,
NestedTypeExclude, NestedTypeExclude,
NestedTypeCount, NestedTypeCount,
NestedVisibility,
EventsInclude, EventsInclude,
EventsExclude EventsExclude
} }

View File

@ -56,7 +56,6 @@ public class SearchParams
public class GenericParams public class GenericParams
{ {
public bool IsPublic { get; set; } = true; public bool IsPublic { get; set; } = true;
public bool? IsAbstract { get; set; } = null; public bool? IsAbstract { get; set; } = null;
public bool? IsInterface { get; set; } = null; public bool? IsInterface { get; set; } = null;
public bool? IsStruct { get; set; } = null; public bool? IsStruct { get; set; } = null;
@ -97,6 +96,12 @@ public class PropertyParams
public class NestedTypeParams public class NestedTypeParams
{ {
public bool IsNested { get; set; } public bool IsNested { get; set; }
public bool IsNestedAssembly { get; set; }
public bool IsNestedFamily { get; set; }
public bool IsNestedPrivate { get; set; }
public bool IsNestedPublic { get; set; }
public bool IsNestedFamilyAndAssembly { get; set; }
public bool IsNestedFamilyOrAssembly { get; set; }
/// <summary> /// <summary>
/// Name of the nested types parent /// Name of the nested types parent

View File

@ -22,9 +22,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
out var module); out var module);
Module = module; Module = module;
CandidateTypes = Module.GetTypes()
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
.ToList();
var targetTypeDef = FindTargetType(oldTypeName); var targetTypeDef = FindTargetType(oldTypeName);
@ -36,9 +33,24 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
Logger.LogSync($"Found target type: {targetTypeDef!.FullName}", ConsoleColor.Green); Logger.LogSync($"Found target type: {targetTypeDef!.FullName}", ConsoleColor.Green);
var remapModel = new RemapModel(); if (targetTypeDef.IsNested)
remapModel.NewTypeName = newTypeName; {
remapModel.AutoGenerated = true; CandidateTypes = targetTypeDef.DeclaringType.NestedTypes
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
.ToList();
}
else
{
CandidateTypes = Module.Types
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
.ToList();
}
var remapModel = new RemapModel()
{
NewTypeName = newTypeName,
AutoGenerated = true
};
StartFilter(targetTypeDef, remapModel, assemblyPath); StartFilter(targetTypeDef, remapModel, assemblyPath);
} }
@ -57,36 +69,42 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
{ {
if (!PassesGeneralChecks(target, candidate, remapModel.SearchParams.GenericParams)) if (!PassesGeneralChecks(target, candidate, remapModel.SearchParams.GenericParams))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after general checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
continue; continue;
} }
if (!ContainsTargetMethods(target, candidate, remapModel.SearchParams.Methods)) if (!ContainsTargetMethods(target, candidate, remapModel.SearchParams.Methods))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after method checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
continue; continue;
} }
if (!ContainsTargetFields(target, candidate, remapModel.SearchParams.Fields)) if (!ContainsTargetFields(target, candidate, remapModel.SearchParams.Fields))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after field checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
continue; continue;
} }
if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties)) if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after property checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
continue; continue;
} }
if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes)) if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after nested checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
continue; continue;
} }
if (!ContainsTargetEvents(target, candidate, remapModel.SearchParams.Events)) if (!ContainsTargetEvents(target, candidate, remapModel.SearchParams.Events))
{ {
Logger.LogSync($"Candidate: {candidate.Name} filtered out after event checks", ConsoleColor.Yellow);
CandidateTypes!.Remove(candidate); CandidateTypes!.Remove(candidate);
} }
} }
@ -102,8 +120,10 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true); new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
if (remapModel.Succeeded)
{
ProcessEndQuestions(remapModel, assemblyPath); ProcessEndQuestions(remapModel, assemblyPath);
return; }
} }
Logger.LogSync("Could not find a match... :(", ConsoleColor.Red); Logger.LogSync("Could not find a match... :(", ConsoleColor.Red);
@ -183,7 +203,8 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
methods.ConstructorParameterCount = target.Methods.First(m => m.IsConstructor && m.Parameters.Count > 0).Parameters.Count - 1; methods.ConstructorParameterCount = target.Methods.First(m => m.IsConstructor && m.Parameters.Count > 0).Parameters.Count - 1;
} }
return commonMethods.Any(); // True if we have common methods, or all methods are constructors
return commonMethods.Any() || target.Methods.All(m => m.IsConstructor);
} }
private bool ContainsTargetFields(TypeDef target, TypeDef candidate, FieldParams fields) private bool ContainsTargetFields(TypeDef target, TypeDef candidate, FieldParams fields)
@ -294,13 +315,19 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
nt.NestedTypeCount = target.NestedTypes.Count; nt.NestedTypeCount = target.NestedTypes.Count;
nt.IsNested = target.IsNested; nt.IsNested = target.IsNested;
nt.IsNestedAssembly = target.IsNestedAssembly;
nt.IsNestedFamily = target.IsNestedFamily;
nt.IsNestedPrivate = target.IsNestedPrivate;
nt.IsNestedPublic = target.IsNestedPublic;
nt.IsNestedFamilyAndAssembly = target.IsNestedFamilyAndAssembly;
nt.IsNestedFamilyOrAssembly = target.IsNestedFamilyOrAssembly;
if (target.DeclaringType is not null) if (target.DeclaringType is not null)
{ {
nt.NestedTypeParentName = target.DeclaringType.Name.String; nt.NestedTypeParentName = target.DeclaringType.Name.String;
} }
return commonNts.Any() || !target.IsNested; return commonNts.Any() || target.NestedTypes.Count == 0;
} }
private bool ContainsTargetEvents(TypeDef target, TypeDef candidate, EventParams events) private bool ContainsTargetEvents(TypeDef target, TypeDef candidate, EventParams events)

View File

@ -1,5 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
using ReCodeItLib.Models; using ReCodeItLib.Models;
using ReCodeItLib.Utils;
namespace ReCodeItLib.ReMapper.Filters; namespace ReCodeItLib.ReMapper.Filters;
@ -14,48 +15,7 @@ internal static class GenericTypeFilters
/// <returns>Filtered list</returns> /// <returns>Filtered list</returns>
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms) public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
{ {
// REQUIRED PROPERTY return types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
if (parms.GenericParams.IsPublic)
{
if (parms.NestedTypes.IsNested is true)
{
types = types.Where(t => t.IsNestedPublic);
types = FilterNestedByName(types, parms);
}
else
{
types = types.Where(t => t.IsPublic);
}
}
else
{
if (parms.NestedTypes.IsNested is true)
{
types = types.Where(t => t.IsNestedPrivate
|| t.IsNestedFamily
|| t.IsNestedFamilyAndAssembly
|| t.IsNestedAssembly);
types = FilterNestedByName(types, parms);
}
else
{
types = types.Where(t => t.IsNotPublic);
}
}
return types;
}
private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms)
{
if (parms.NestedTypes.NestedTypeParentName is not "")
{
types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName);
}
return types;
} }
/// <summary> /// <summary>

View File

@ -71,4 +71,32 @@ internal static class NestedTypeFilters
return types; return types;
} }
public static IEnumerable<TypeDef> FilterByNestedVisibility(IEnumerable<TypeDef> types, SearchParams parms)
{
types = FilterNestedByName(types, parms);
var ntp = parms.NestedTypes;
types = types.Where(t =>
t.IsNestedAssembly == ntp.IsNestedAssembly
&& t.IsNestedFamily == ntp.IsNestedFamily
&& t.IsNestedPrivate == ntp.IsNestedPrivate
&& t.IsNestedPublic == ntp.IsNestedPublic
&& t.IsNestedFamilyAndAssembly == ntp.IsNestedFamilyAndAssembly
&& t.IsNestedFamilyOrAssembly == ntp.IsNestedFamilyOrAssembly
);
return types;
}
private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms)
{
if (parms.NestedTypes.NestedTypeParentName is not "")
{
types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName);
}
return types;
}
} }

View File

@ -9,7 +9,7 @@ internal class Publicizer
{ {
var types = definition.GetTypes(); var types = definition.GetTypes();
var publicizeTasks = new List<Task>(); var publicizeTasks = new List<Task>(types.Count(t => !t.IsNested));
foreach (var type in types) foreach (var type in types)
{ {
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
@ -25,7 +25,7 @@ internal class Publicizer
// TODO: This is broken. No idea why. // TODO: This is broken. No idea why.
while (!publicizeTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) while (!publicizeTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
{ {
Logger.DrawProgressBar(publicizeTasks.Where(t => t.IsCompleted)!.Count() + 1, publicizeTasks.Count, 50); Logger.DrawProgressBar(publicizeTasks.Count(t => t.IsCompleted), publicizeTasks.Count, 50);
} }
Task.WaitAll(publicizeTasks.ToArray()); Task.WaitAll(publicizeTasks.ToArray());

View File

@ -173,15 +173,9 @@ public class ReMapper
} }
// Filter down nested objects // Filter down nested objects
if (mapping.SearchParams.NestedTypes.IsNested is false) types = !mapping.SearchParams.NestedTypes.IsNested
{ ? types.Where(type => tokens!.Any(token => type.Name.StartsWith(token)))
types = types.Where(type => tokens!.Any(token => type.Name.StartsWith(token))); : types.Where(t => t.DeclaringType != null && t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName);
}
if (mapping.SearchParams.NestedTypes.NestedTypeParentName != string.Empty)
{
types = types.Where(t => t.DeclaringType != null && t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName);
}
// Run through a series of filters and report an error if all types are filtered out. // Run through a series of filters and report an error if all types are filtered out.
var filters = new TypeFilters(); var filters = new TypeFilters();

View File

@ -16,11 +16,7 @@ internal class Renamer
/// <param name="direct"></param> /// <param name="direct"></param>
public void RenameAll(IEnumerable<TypeDef> types, RemapModel remap) public void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
{ {
if (remap.TypePrimeCandidate is null) if (remap.TypePrimeCandidate is null) return;
{
Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
return;
}
// Rename all fields and properties first // Rename all fields and properties first
RenameAllFields( RenameAllFields(

View File

@ -53,15 +53,18 @@ public class Statistics(
foreach (var remap in remapModels) foreach (var remap in remapModels)
{ {
if (remap.Succeeded is false && remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch)) switch (remap.Succeeded)
{ {
case false when remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch):
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red); Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red); Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red);
Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red); Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red);
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red); Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
}
else if (remap.Succeeded is false) failures++;
break;
case false:
{ {
Logger.Log("-----------------------------------------------", ConsoleColor.Red); Logger.Log("-----------------------------------------------", ConsoleColor.Red);
Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red); Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red);
@ -75,6 +78,7 @@ public class Statistics(
failures++; failures++;
continue; continue;
} }
}
if (validate && remap.Succeeded) if (validate && remap.Succeeded)
{ {

View File

@ -26,7 +26,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); AddNoMatchReason(mapping, ENoMatchReason.IsPublic);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -35,7 +35,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic); AddNoMatchReason(mapping, ENoMatchReason.IsAbstract);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -44,7 +44,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsSealed); AddNoMatchReason(mapping, ENoMatchReason.IsSealed);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -53,7 +53,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsInterface); AddNoMatchReason(mapping, ENoMatchReason.IsInterface);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -62,7 +62,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsStruct); AddNoMatchReason(mapping, ENoMatchReason.IsStruct);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -71,7 +71,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsEnum); AddNoMatchReason(mapping, ENoMatchReason.IsEnum);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -80,7 +80,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.HasAttribute); AddNoMatchReason(mapping, ENoMatchReason.HasAttribute);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -89,7 +89,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsDerived); AddNoMatchReason(mapping, ENoMatchReason.IsDerived);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -98,7 +98,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.HasGenericParameters); AddNoMatchReason(mapping, ENoMatchReason.HasGenericParameters);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -112,7 +112,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsInclude); AddNoMatchReason(mapping, ENoMatchReason.MethodsInclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -121,7 +121,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsExclude); AddNoMatchReason(mapping, ENoMatchReason.MethodsExclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -130,7 +130,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsCount); AddNoMatchReason(mapping, ENoMatchReason.MethodsCount);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -139,7 +139,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.ConstructorParameterCount); AddNoMatchReason(mapping, ENoMatchReason.ConstructorParameterCount);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -153,7 +153,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsInclude); AddNoMatchReason(mapping, ENoMatchReason.FieldsInclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -162,7 +162,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsExclude); AddNoMatchReason(mapping, ENoMatchReason.FieldsExclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -171,7 +171,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsCount); AddNoMatchReason(mapping, ENoMatchReason.FieldsCount);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -185,7 +185,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude); AddNoMatchReason(mapping, ENoMatchReason.PropertiesInclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -194,7 +194,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude); AddNoMatchReason(mapping, ENoMatchReason.PropertiesExclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -203,7 +203,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesCount); AddNoMatchReason(mapping, ENoMatchReason.PropertiesCount);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -217,7 +217,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeInclude); AddNoMatchReason(mapping, ENoMatchReason.NestedTypeInclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -226,7 +226,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeExclude); AddNoMatchReason(mapping, ENoMatchReason.NestedTypeExclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -235,7 +235,16 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeCount); AddNoMatchReason(mapping, ENoMatchReason.NestedTypeCount);
mapping.TypeCandidates.UnionWith(types);
return false;
}
types = NestedTypeFilters.FilterByNestedVisibility(types, mapping.SearchParams);
if (!types.Any())
{
AddNoMatchReason(mapping, ENoMatchReason.NestedVisibility);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -249,7 +258,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsInclude); AddNoMatchReason(mapping, ENoMatchReason.EventsInclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -258,7 +267,7 @@ public class TypeFilters
if (!types.Any()) if (!types.Any())
{ {
AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsExclude); AddNoMatchReason(mapping, ENoMatchReason.EventsExclude);
mapping.TypeCandidates.UnionWith(types); mapping.TypeCandidates.UnionWith(types);
return false; return false;
} }
@ -266,13 +275,8 @@ public class TypeFilters
return true; return true;
} }
/// <summary> private static void AddNoMatchReason(RemapModel remap, ENoMatchReason noMatchReason)
/// This is used to log that all types for a given remap were filtered out.
/// </summary>
/// <param name="remap">remap model that failed</param>
/// <param name="noMatchReason">Reason for filtering</param>
private static void AllTypesFilteredOutFor(RemapModel remap, ENoMatchReason noMatchReason)
{ {
Logger.Log($"All types filtered out after `{noMatchReason}` filter for: `{remap.NewTypeName}`", ConsoleColor.Red); remap.NoMatchReasons.Add(noMatchReason);
} }
} }