mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-27 04:25:39 -05:00
Did something similar for NHSE years ago. Allows for much easier reuse elsewhere and clearer usage.
20 lines
821 B
C#
20 lines
821 B
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <inheritdoc cref="IComplexSet"/>
|
|
public sealed class ComplexSet([ConstantExpected] string PropertyName, Action<PKM, StringInstruction> Action) : IComplexSet
|
|
{
|
|
public readonly string PropertyName = PropertyName;
|
|
public readonly Func<ReadOnlySpan<char>, bool> IsValueCompatible = _ => true;
|
|
|
|
public ComplexSet([ConstantExpected] string PropertyName, Func<ReadOnlySpan<char>, bool> criteria, Action<PKM, StringInstruction> Action)
|
|
: this(PropertyName, Action) => IsValueCompatible = criteria;
|
|
|
|
public bool IsMatch(ReadOnlySpan<char> name, ReadOnlySpan<char> value)
|
|
=> name.SequenceEqual(PropertyName) && IsValueCompatible(value);
|
|
|
|
public void Modify(PKM pk, StringInstruction instr) => Action(pk, instr);
|
|
}
|