Struct LocalPath
- Namespace
- TruePath
- Assembly
- TruePath.dll
A path pointing to a place in the local file system.
It may be either absolute or relative.
Always stored in a normalized form. Read the documentation on Normalize(string) to know what form of normalization does the path use.
public readonly struct LocalPath : IEquatable<LocalPath>, IPath, IPath<LocalPath>
- Implements
- Inherited Members
- Extension Methods
Constructors
LocalPath(string)
A path pointing to a place in the local file system.
It may be either absolute or relative.
Always stored in a normalized form. Read the documentation on Normalize(string) to know what form of normalization does the path use.
public LocalPath(string value)
Parameters
value
string
LocalPath(AbsolutePath)
Converts an AbsolutePath to a LocalPath.
public LocalPath(AbsolutePath path)
Parameters
path
AbsolutePath
Fields
PlatformDefaultComparer
Provides a default comparer for comparing file paths, aware of the current platform.
On Windows and macOS, this will perform case-insensitive string comparison, since the file systems are case-insensitive on these operating systems by default.
On Linux, the comparison will be case-sensitive.
public static readonly IEqualityComparer<LocalPath> PlatformDefaultComparer
Field Value
Remarks
Note that this comparison does not guarantee correctness: in practice, on any platform to control case-sensitiveness of either the whole file system or a part of it. This class does not take this into account, having a benefit of no accessing the file system for any of the comparisons.
StrictStringComparer
A strict comparer for comparing file paths using ordinal, case-sensitive comparison of the underlying path strings.
public static readonly IEqualityComparer<LocalPath> StrictStringComparer
Field Value
Properties
FileName
The name of the last component of this path.
public string FileName { get; }
Property Value
IsAbsolute
Checks whether th path is absolute.
Currently, any rooted paths are considered absolute, but this is a subject to change: on Windows, there will be an additional requirement for a path to be either a DOS device path or start from a disk letter.
public bool IsAbsolute { get; }
Property Value
Parent
The parent of this path. Will be null
for a rooted absolute path. For a relative path, will always
resolve to its parent directory — by either removing directories from the end of the path, or appending
..
to the end.
public LocalPath? Parent { get; }
Property Value
Value
The normalized path string.
public string Value { get; }
Property Value
Methods
Equals(object?)
Compares the path with another.
public override bool Equals(object? obj)
Parameters
obj
object
Returns
Remarks
Note that currently this comparison is case-sensitive.
Equals(LocalPath)
Compares the path with another.
public bool Equals(LocalPath other)
Parameters
other
LocalPath
Returns
Remarks
Note that currently this comparison is case-sensitive.
Equals(LocalPath, IEqualityComparer<LocalPath>)
Determines whether the specified LocalPath is equal to the current LocalPath using the specified string comparer.
public bool Equals(LocalPath other, IEqualityComparer<LocalPath> comparer)
Parameters
other
LocalPathcomparer
IEqualityComparer<LocalPath>The comparer to use for comparing the paths.
Returns
- bool
true if the specified LocalPath is equal to the current LocalPath using the specified string comparer; otherwise, false.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
IsPrefixOf(LocalPath)
public bool IsPrefixOf(LocalPath other)
Parameters
other
LocalPath
Returns
Remarks
Checks for a non-strict prefix: if the paths are equal then they are still considered prefixes of each other.
RelativeTo(LocalPath)
Calculates the relative path from a base path to this path.
public LocalPath RelativeTo(LocalPath basePath)
Parameters
basePath
LocalPathThe base path from which to calculate the relative path.
Returns
- LocalPath
The relative path from the base path to this path.
ResolveToCurrentDirectory()
Resolves this path to an absolute path based on the current working directory.
public AbsolutePath ResolveToCurrentDirectory()
Returns
- AbsolutePath
An AbsolutePath that represents this path resolved against the current working directory.
Remarks
Note that if this path is already absolute, it will just transform to AbsolutePath. The current directory won't matter for such a case.
StartsWith(LocalPath)
Determines whether the current path starts with the specified path.
public bool StartsWith(LocalPath other)
Parameters
other
LocalPathThe path to compare to the current path.
Returns
Remarks
Note that currently this comparison is case-sensitive.
ToString()
public override string ToString()
Returns
- string
The normalized path string contained in this object.
Operators
operator /(LocalPath, string)
Appends another path to this one.
public static LocalPath operator /(LocalPath basePath, string b)
Parameters
Returns
Remarks
Note that in case path b
is absolute, it will completely take over and the
basePath
will be ignored.
operator /(LocalPath, LocalPath)
Appends another path to this one.
public static LocalPath operator /(LocalPath basePath, LocalPath b)
Parameters
Returns
Remarks
Note that in case path b
is absolute, it will completely take over and the
basePath
will be ignored.
operator ==(LocalPath, LocalPath)
Compares the path with another.
public static bool operator ==(LocalPath left, LocalPath right)
Parameters
Returns
Remarks
Note that currently this comparison is case-sensitive.
implicit operator LocalPath(AbsolutePath)
Implicitly converts an AbsolutePath to a LocalPath.
public static implicit operator LocalPath(AbsolutePath path)
Parameters
path
AbsolutePath
Returns
Remarks
Note that this conversion doesn't lose any information.
operator !=(LocalPath, LocalPath)
Compares the path with another.
public static bool operator !=(LocalPath left, LocalPath right)
Parameters
Returns
Remarks
Note that currently this comparison is case-sensitive.