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

36 lines
962 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
2022-09-06 05:53:22 +00:00
using MfGames.Gallium;
2022-09-06 05:53:22 +00:00
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)
{
this.validator.ValidateAndThrow(this);
return input.Select(
(entity) => this.HasHandlebarsTest.Invoke(entity) ? entity.Set(HasHandlebarsTemplate.Instance) : entity);
}
}