28 lines
851 B
C#
Raw Normal View History

2024-06-14 19:06:21 -04:00
using ReCodeIt.Enums;
using ReCodeIt.Models;
2024-06-13 04:56:08 -04:00
using Mono.Cecil;
using Mono.Cecil.Rocks;
2024-06-14 19:06:21 -04:00
namespace ReCodeIt.ReMapper.Search;
2024-06-13 04:56:08 -04:00
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
}
}