PKHeX/PKHeX.Core/Editing/Bulk/ComplexSet/ComplexSet.cs
Kurt e2086d2a0d Misc tweaks
Allow pkm batch editor to take readonlyspan property names
concrete types over `default` for clarity
encounterverifier: use const values for egg levels for clarity
batchediting: fetch all properties only once
etrade4: reduce object size/init by having Contest as a property
2024-12-31 12:53:51 -06:00

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);
}