using AssemblyRemapper.Enums;
using AssemblyRemapper.Models;
using Mono.Cecil;
using MoreLinq;
namespace AssemblyRemapper.Remapper.Search;
internal static class Methods
{
///
/// returns a match on all types with the specified methods
///
///
///
///
/// Match if type contains any supplied methods
public static EMatchResult GetTypeWithMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.MatchMethods is null || parms.MatchMethods.Count == 0) return EMatchResult.Disabled;
var matches = type.Methods
.Where(method => parms.MatchMethods.Contains(method.Name))
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
///
/// Returns a match on all types without methods
///
///
///
///
/// Match if type has no methods
public static EMatchResult GetTypeWithoutMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.IgnoreMethods is null || parms.IgnoreMethods.Count == 0) return EMatchResult.Disabled;
var matches = type.Methods
.Where(method => parms.IgnoreMethods.Contains(method.Name))
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
public static EMatchResult GetTypeByNumberOfMethods(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.MethodCount is null) return EMatchResult.Disabled;
var match = type.Methods.Exactly((int)parms.MethodCount);
if (match) { score.Score++; }
return match
? EMatchResult.Match
: EMatchResult.NoMatch;
}
}