using System;
using System.Collections.Generic;
using Gallium;
using Zio;
namespace Nitride.IO.Paths
{
///
/// Changes the extension of the paths given.
///
[WithProperties]
public partial class ChangePathExtension : INitrideOperation
{
public ChangePathExtension()
{
}
public ChangePathExtension(string extension)
{
this.Extension = extension;
}
///
/// Gets or sets the prefix for the path operations.
///
public string? Extension { get; set; }
public IEnumerable Run(IEnumerable input)
{
if (this.Extension == null)
{
throw new InvalidOperationException(
nameof(AddPathPrefix)
+ ".Extension was not set "
+ "(via constructor, property, or SetExtension) before "
+ "Run() was called.");
}
ReplacePaths replacePaths = new ReplacePaths()
.WithReplacement(this.RunReplacement);
return replacePaths.Run(input);
}
private UPath RunReplacement(Entity _, UPath path)
{
return path.ChangeExtension(this.Extension!);
}
}
}