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.IO/Paths/AddPathPrefix.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

54 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.Threading;
using FluentValidation;
using MfGames.Gallium;
using MfGames.Nitride.Generators;
using Zio;
namespace MfGames.Nitride.IO.Paths;
[WithProperties]
public partial class AddPathPrefix : OperationBase
{
private readonly ReplacePath replacePath;
private readonly IValidator<AddPathPrefix> validator;
public AddPathPrefix(
IValidator<AddPathPrefix> validator,
ReplacePath replacePath)
{
this.validator = validator;
this.replacePath = replacePath;
}
/// <summary>
/// Gets or sets the prefix for the path operations.
/// </summary>
public UPath? PathPrefix { get; set; }
public override IEnumerable<Entity> Run(
IEnumerable<Entity> input,
CancellationToken cancellationToken = default)
{
this.validator.ValidateAndThrow(this);
return this.replacePath
.WithReplacement(this.RunReplacement)
.Run(input);
}
private UPath RunReplacement(
Entity _,
UPath path)
{
string innerRelativePath = path.ToString()
.TrimStart('/');
return this.PathPrefix!.Value / innerRelativePath;
}
}