This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.Handlebars/IdentifyHandlebarsFromComponent.cs
D. Moonfire 2892ec3445
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
feat!: added cancellation token support to pipelines and operations
2023-01-17 19:24:09 -06:00

43 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FluentValidation;
using MfGames.Gallium;
using MfGames.Nitride.Generators;
namespace MfGames.Nitride.Handlebars;
/// <summary>
/// An operation that discovers which text files have a Handlebars template
/// based on a component.
/// </summary>
[WithProperties]
public partial class IdentifyHandlebarsFromComponent : IOperation
{
private readonly IValidator<IdentifyHandlebarsFromComponent> validator;
public IdentifyHandlebarsFromComponent(
IValidator<IdentifyHandlebarsFromComponent> validator)
{
this.validator = validator;
}
public Func<Entity, bool> HasHandlebarsTest { get; set; } = null!;
/// <inheritdoc />
public IEnumerable<Entity> Run(
IEnumerable<Entity> input,
CancellationToken cancellationToken = default)
{
this.validator.ValidateAndThrow(this);
return input.Select(
(entity) => this.HasHandlebarsTest.Invoke(entity)
? entity.Set(HasHandlebarsTemplate.Instance)
: entity);
}
}