Skip to content

[API Proposal]: NameWithoutExtension #129

Description

@dennisdoomen

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions