File: FilePath.cs
Web Access
Project: src\sdk\src\Cli\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj (Microsoft.DotNet.InternalAbstractions)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.Extensions.EnvironmentAbstractions;

public readonly struct FilePath
{
    public string Value { get; }

    /// <summary>
    /// Create FilePath to represent an absolute file path. Note: It may not exist.
    /// </summary>
    /// <param name="value">If the value is not rooted. Path.GetFullPath will be called during the constructor.</param>
    public FilePath(string value)
    {
        if (!Path.IsPathRooted(value))
        {
            value = Path.GetFullPath(value);
        }

        Value = value;
    }

    public override string ToString()
    {
        return Value;
    }

    public DirectoryPath GetDirectoryPath()
    {
        return new DirectoryPath(Path.GetDirectoryName(Value)!);
    }
}