mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 17:10:45 -05:00
Small refactor to type filters
This commit is contained in:
parent
75f418417c
commit
701e302cc6
@ -1,84 +0,0 @@
|
|||||||
using dnlib.DotNet;
|
|
||||||
using ReCodeItLib.Models;
|
|
||||||
using ReCodeItLib.Utils;
|
|
||||||
|
|
||||||
namespace ReCodeItLib.ReMapper.Filters;
|
|
||||||
|
|
||||||
internal static class GenericTypeFilters
|
|
||||||
{
|
|
||||||
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
return types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterAbstract(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
// NOTE: Interfaces are abstract
|
|
||||||
return types.Where(t => t.IsAbstract == parms.GenericParams.IsAbstract);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterSealed(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
return types.Where(t => t.IsSealed == parms.GenericParams.IsSealed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterInterface(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
// Filter based on interface or not
|
|
||||||
if (parms.GenericParams.IsInterface is true)
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.IsInterface);
|
|
||||||
}
|
|
||||||
else if (parms.GenericParams.IsInterface is false)
|
|
||||||
{
|
|
||||||
types = types.Where(t => !t.IsInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterEnum(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
return types.Where(t => t.IsEnum == parms.GenericParams.IsEnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
// Filter based on HasAttribute or not
|
|
||||||
if (parms.GenericParams.HasAttribute is true)
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.HasCustomAttributes);
|
|
||||||
}
|
|
||||||
else if (parms.GenericParams.HasAttribute is false)
|
|
||||||
{
|
|
||||||
types = types.Where(t => !t.HasCustomAttributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
// Filter based on IsDerived or not
|
|
||||||
if (parms.GenericParams.IsDerived is true)
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.GetBaseType()?.Name?.String != "Object");
|
|
||||||
|
|
||||||
if (parms.GenericParams.MatchBaseClass is not null and not "")
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (parms.GenericParams.IsDerived is false)
|
|
||||||
{
|
|
||||||
types = types.Where(t => t.GetBaseType()?.Name?.String is "Object");
|
|
||||||
}
|
|
||||||
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TypeDef> FilterByGenericParameters(IEnumerable<TypeDef> types, SearchParams parms)
|
|
||||||
{
|
|
||||||
return types.Where(t => t.HasGenericParameters == parms.GenericParams.HasGenericParameters);
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,9 @@ public class TypeFilters
|
|||||||
|
|
||||||
private static bool FilterTypesByGeneric(RemapModel mapping, ref IEnumerable<TypeDef> types)
|
private static bool FilterTypesByGeneric(RemapModel mapping, ref IEnumerable<TypeDef> types)
|
||||||
{
|
{
|
||||||
types = GenericTypeFilters.FilterPublic(types, mapping.SearchParams);
|
var parms = mapping.SearchParams;
|
||||||
|
|
||||||
|
types = types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -31,7 +33,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterAbstract(types, mapping.SearchParams);
|
types = types.Where(t => t.IsAbstract == parms.GenericParams.IsAbstract);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -40,7 +42,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterSealed(types, mapping.SearchParams);
|
types = types.Where(t => t.IsSealed == parms.GenericParams.IsSealed);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -48,8 +50,8 @@ public class TypeFilters
|
|||||||
mapping.TypeCandidates.UnionWith(types);
|
mapping.TypeCandidates.UnionWith(types);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterInterface(types, mapping.SearchParams);
|
types = types.Where(t => t.IsInterface == parms.GenericParams.IsInterface);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -58,7 +60,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterEnum(types, mapping.SearchParams);
|
types = types.Where(t => t.IsEnum == parms.GenericParams.IsEnum);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -67,7 +69,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterAttributes(types, mapping.SearchParams);
|
types = FilterAttributes(types, mapping.SearchParams);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -76,7 +78,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterDerived(types, mapping.SearchParams);
|
types = FilterDerived(types, mapping.SearchParams);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -85,7 +87,7 @@ public class TypeFilters
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
types = GenericTypeFilters.FilterByGenericParameters(types, mapping.SearchParams);
|
types = types.Where(t => t.HasGenericParameters == parms.GenericParams.HasGenericParameters);
|
||||||
|
|
||||||
if (!types.Any())
|
if (!types.Any())
|
||||||
{
|
{
|
||||||
@ -266,6 +268,41 @@ public class TypeFilters
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
|
{
|
||||||
|
// Filter based on HasAttribute or not
|
||||||
|
if (parms.GenericParams.HasAttribute is true)
|
||||||
|
{
|
||||||
|
types = types.Where(t => t.HasCustomAttributes);
|
||||||
|
}
|
||||||
|
else if (parms.GenericParams.HasAttribute is false)
|
||||||
|
{
|
||||||
|
types = types.Where(t => !t.HasCustomAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
||||||
|
{
|
||||||
|
// Filter based on IsDerived or not
|
||||||
|
if (parms.GenericParams.IsDerived is true)
|
||||||
|
{
|
||||||
|
types = types.Where(t => t.GetBaseType()?.Name?.String != "Object");
|
||||||
|
|
||||||
|
if (parms.GenericParams.MatchBaseClass is not null and not "")
|
||||||
|
{
|
||||||
|
types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (parms.GenericParams.IsDerived is false)
|
||||||
|
{
|
||||||
|
types = types.Where(t => t.GetBaseType()?.Name?.String is "Object");
|
||||||
|
}
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
private static void AddNoMatchReason(RemapModel remap, ENoMatchReason noMatchReason)
|
private static void AddNoMatchReason(RemapModel remap, ENoMatchReason noMatchReason)
|
||||||
{
|
{
|
||||||
remap.NoMatchReasons.Add(noMatchReason);
|
remap.NoMatchReasons.Add(noMatchReason);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user