using AssemblyRemapper.Enums;
using AssemblyRemapper.Models;
using Mono.Cecil;
using MoreLinq;
namespace AssemblyRemapper.Remapper.Search;
internal static class Fields
{
///
/// Returns a match on any type with the provided fields
///
///
///
///
///
public static EMatchResult GetTypeWithFields(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.MatchFields is null || parms.MatchFields.Count == 0) return EMatchResult.Disabled;
var matches = type.Fields
.Where(field => parms.MatchFields.Contains(field.Name))
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
///
/// Returns a match on any type without the provided fields
///
///
///
///
///
public static EMatchResult GetTypeWithoutFields(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.IgnoreFields is null || parms.IgnoreFields.Count == 0) return EMatchResult.Disabled;
var matches = type.Fields
.Where(field => parms.IgnoreFields.Contains(field.Name))
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
///
/// Returns a match on any type with a matching number of fields
///
///
///
///
///
public static EMatchResult GetTypeByNumberOfFields(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.FieldCount is null) return EMatchResult.Disabled;
var match = type.Fields.Exactly((int)parms.FieldCount);
if (match) { score.Score++; }
return match
? EMatchResult.Match
: EMatchResult.NoMatch;
}
}