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
Dylan R. E. Moonfire 78054ee2a7 feat: initial release
2021-09-07 00:15:45 -05:00

51 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using Gallium;
using Zio;
namespace Nitride.IO.Paths
{
/// <summary>
/// Changes the extension of the paths given.
/// </summary>
[WithProperties]
public partial class ChangePathExtension : INitrideOperation
{
public ChangePathExtension()
{
}
public ChangePathExtension(string extension)
{
this.Extension = extension;
}
/// <summary>
/// Gets or sets the prefix for the path operations.
/// </summary>
public string? Extension { get; set; }
public IEnumerable<Entity> Run(IEnumerable<Entity> 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!);
}
}
}