49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Gallium;
|
|
using Zio;
|
|
|
|
namespace Nitride.IO.Paths
|
|
{
|
|
[WithProperties]
|
|
public partial class AddPathPrefix : INitrideOperation
|
|
{
|
|
public AddPathPrefix()
|
|
{
|
|
}
|
|
|
|
public AddPathPrefix(UPath pathPrefix)
|
|
{
|
|
this.PathPrefix = pathPrefix;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the prefix for the path operations.
|
|
/// </summary>
|
|
public UPath? PathPrefix { get; set; }
|
|
|
|
public IEnumerable<Entity> Run(IEnumerable<Entity> input)
|
|
{
|
|
if (this.PathPrefix == null)
|
|
{
|
|
throw new InvalidOperationException(
|
|
nameof(AddPathPrefix)
|
|
+ ".Prefix was not set "
|
|
+ "(via constructor, property, or SetPrefix) before "
|
|
+ "Run() was called.");
|
|
}
|
|
|
|
ReplacePaths replacePaths = new ReplacePaths()
|
|
.WithReplacement(this.RunReplacement);
|
|
|
|
return replacePaths.Run(input);
|
|
}
|
|
|
|
private UPath RunReplacement(Entity _, UPath path)
|
|
{
|
|
string innerRelativePath = path.ToString().TrimStart('/');
|
|
return this.PathPrefix!.Value / innerRelativePath;
|
|
}
|
|
}
|
|
}
|