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/Nitride.IO/Paths/ChangePathExtension.cs

44 lines
1 KiB
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using System.Collections.Generic;
using FluentValidation;
2021-09-07 05:15:45 +00:00
using Gallium;
2021-09-07 05:15:45 +00:00
using Zio;
namespace Nitride.IO.Paths;
/// <summary>
/// Changes the extension of the paths given.
/// </summary>
[WithProperties]
public partial class ChangePathExtension : IOperation
2021-09-07 05:15:45 +00:00
{
private readonly ReplacePath replacePath;
private readonly IValidator<ChangePathExtension> validator;
public ChangePathExtension(IValidator<ChangePathExtension> validator, ReplacePath replacePath)
{
this.validator = validator;
this.replacePath = replacePath;
}
2021-09-07 05:15:45 +00:00
/// <summary>
/// Gets or sets the prefix for the path operations.
2021-09-07 05:15:45 +00:00
/// </summary>
public string? Extension { get; set; }
public IEnumerable<Entity> Run(IEnumerable<Entity> input)
{
this.validator.ValidateAndThrow(this);
return this.replacePath.WithReplacement(this.RunReplacement).Run(input);
}
private UPath RunReplacement(Entity _, UPath path)
2021-09-07 05:15:45 +00:00
{
return path.ChangeExtension(this.Extension!);
2021-09-07 05:15:45 +00:00
}
}