Background and motivation
Name gives the file name including the extension and Extension gives the extension including the dot, but there is no property for the file name without the extension. This is a very common need (deriving an assembly name from a project file, naming an output artifact after its input, building a report name). Today callers have to write Path.GetFileNameWithoutExtension(path.ToString()), which drops out of the fluent style the library is built around.
API Proposal
namespace Pathy
{
public readonly struct ChainablePath
{
public string NameWithoutExtension { get; }
}
}
API Usage
var project = ChainablePath.From("c:/work/repo/src/Pathy/Pathy.csproj");
project.Name; // "Pathy.csproj"
project.Extension; // ".csproj"
project.NameWithoutExtension; // "Pathy"
var package = artifactsDirectory / (project.NameWithoutExtension + ".nupkg");
Alternative Designs
A WithoutExtension() method that returns a ChainablePath covers a related but different need: it keeps the directory. Both are useful, and this proposal is only about the string property. See the separate proposal for WithExtension, WithName and WithoutExtension.
Risks
Behaviour on names such as .gitignore and archive.tar.gz needs to be documented explicitly. Matching Path.GetFileNameWithoutExtension is the least surprising choice.
Background and motivation
Namegives the file name including the extension andExtensiongives the extension including the dot, but there is no property for the file name without the extension. This is a very common need (deriving an assembly name from a project file, naming an output artifact after its input, building a report name). Today callers have to writePath.GetFileNameWithoutExtension(path.ToString()), which drops out of the fluent style the library is built around.API Proposal
API Usage
Alternative Designs
A
WithoutExtension()method that returns aChainablePathcovers a related but different need: it keeps the directory. Both are useful, and this proposal is only about the string property. See the separate proposal forWithExtension,WithNameandWithoutExtension.Risks
Behaviour on names such as
.gitignoreandarchive.tar.gzneeds to be documented explicitly. MatchingPath.GetFileNameWithoutExtensionis the least surprising choice.