28 lines
875 B
C#
Raw Normal View History

2024-06-13 04:56:08 -04:00
using AssemblyRemapper.Enums;
using AssemblyRemapper.Models;
using Mono.Cecil;
using Mono.Cecil.Rocks;
namespace AssemblyRemapper.Remapper.Search;
internal static class Constructors
{
/// <summary>
/// Search for types with a constructor of a given length
/// </summary>
/// <param name="parms"></param>
/// <param name="score"></param>
/// <returns>Match if constructor parameters matches</returns>
public static EMatchResult GetTypeByParameterCount(TypeDefinition type, SearchParams parms, ScoringModel score)
{
2024-06-13 08:18:16 -04:00
if (parms.ConstructorParameterCount is null) return EMatchResult.Disabled;
2024-06-13 04:56:08 -04:00
2024-06-13 08:18:16 -04:00
var match = type.GetConstructors()
.Where(c => c.Parameters.Count == parms.ConstructorParameterCount)
.Any();
2024-06-13 04:56:08 -04:00
2024-06-13 08:18:16 -04:00
return match
? EMatchResult.Match
: EMatchResult.NoMatch;
2024-06-13 04:56:08 -04:00
}
}