53 lines
1.7 KiB
C#
Raw Normal View History

2024-06-13 08:18:16 -04:00
using AssemblyRemapper.Enums;
using AssemblyRemapper.Models;
using Mono.Cecil;
using MoreLinq;
namespace AssemblyRemapper.Remapper.Search
2024-06-13 04:56:08 -04:00
{
internal class Properties
{
2024-06-13 08:18:16 -04:00
public static EMatchResult IncludeProperties(TypeDefinition type, SearchParams parms, ScoringModel score)
{
2024-06-13 12:32:21 -04:00
if (parms.IncludeProperties is null || parms.IncludeProperties.Count == 0) return EMatchResult.Disabled;
2024-06-13 08:18:16 -04:00
var matches = type.Properties
2024-06-13 12:32:21 -04:00
.Where(property => parms.IncludeProperties.Contains(property.Name))
2024-06-13 08:18:16 -04:00
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
public static EMatchResult ExcludeProperties(TypeDefinition type, SearchParams parms, ScoringModel score)
{
2024-06-13 12:32:21 -04:00
if (parms.ExcludeProperties is null || parms.ExcludeProperties.Count == 0) return EMatchResult.Disabled;
2024-06-13 08:18:16 -04:00
var matches = type.Properties
2024-06-13 12:32:21 -04:00
.Where(property => parms.ExcludeProperties.Contains(property.Name))
2024-06-13 08:18:16 -04:00
.Count();
score.Score += matches;
return matches > 0
? EMatchResult.NoMatch
: EMatchResult.Match;
}
public static EMatchResult MatchPropertyCount(TypeDefinition type, SearchParams parms, ScoringModel score)
{
if (parms.PropertyCount is null) return EMatchResult.Disabled;
var match = type.Properties.Exactly((int)parms.PropertyCount);
if (match) { score.Score++; }
return match
? EMatchResult.Match
: EMatchResult.NoMatch;
}
2024-06-13 04:56:08 -04:00
}
}