58 lines
1.9 KiB
C#
Raw Normal View History

2024-06-17 11:34:06 -04:00
using Mono.Cecil;
2024-06-13 08:18:16 -04:00
using MoreLinq;
2024-06-17 11:34:06 -04:00
using ReCodeIt.Enums;
using ReCodeIt.Models;
2024-06-13 08:18:16 -04:00
2024-06-14 19:06:21 -04:00
namespace ReCodeIt.ReMapper.Search
2024-06-13 04:56:08 -04:00
{
internal class Properties
{
2024-06-17 11:34:06 -04:00
public static EMatchResult Include(TypeDefinition type, SearchParams parms, ScoringModel score)
2024-06-13 08:18:16 -04:00
{
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;
2024-06-14 16:18:43 -04:00
score.FailureReason = matches > 0 ? EFailureReason.None : EFailureReason.PropertiesInclude;
2024-06-13 08:18:16 -04:00
return matches > 0
? EMatchResult.Match
: EMatchResult.NoMatch;
}
2024-06-17 11:34:06 -04:00
public static EMatchResult Exclude(TypeDefinition type, SearchParams parms, ScoringModel score)
2024-06-13 08:18:16 -04:00
{
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();
2024-06-21 05:18:23 -04:00
score.Score -= matches;
2024-06-13 08:18:16 -04:00
2024-06-21 05:18:23 -04:00
score.FailureReason = matches > 0 ? EFailureReason.PropertiesExclude : EFailureReason.None;
2024-06-14 16:18:43 -04:00
2024-06-13 08:18:16 -04:00
return matches > 0
? EMatchResult.NoMatch
: EMatchResult.Match;
}
2024-06-17 11:34:06 -04:00
public static EMatchResult Count(TypeDefinition type, SearchParams parms, ScoringModel score)
2024-06-13 08:18:16 -04:00
{
if (parms.PropertyCount is null) return EMatchResult.Disabled;
var match = type.Properties.Exactly((int)parms.PropertyCount);
if (match) { score.Score++; }
2024-06-14 16:18:43 -04:00
score.FailureReason = match ? EFailureReason.None : EFailureReason.PropertiesCount;
2024-06-13 08:18:16 -04:00
return match
? EMatchResult.Match
: EMatchResult.NoMatch;
}
2024-06-13 04:56:08 -04:00
}
}