Vixen
02b45cc4
csharp
public readonly record struct VirtualPath

An absolute, normalised, case-sensitive path inside the virtual file system.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

One path vocabulary for six platforms. A virtual path always begins with /, uses / as its only separator, has no empty segments, no . or .. left in it, and no trailing slash. Constructing one normalises it; a path that cannot be normalised — one that escapes above the root, or contains a backslash or a control character — is rejected rather than repaired.

Case-sensitive, everywhere, including Windows and macOS. This is the rule from docs/plan/10-platforms.md and it exists because the alternative is discovering on a user's Linux machine that Texture.PNG and texture.png were the same file for the eighteen months the project was developed on a Mac. Two paths that differ in case are two different paths here, and PhysicalFileProvider refuses to serve a file whose real name on disk differs in case from the one asked for.

The default value is the empty path. It is not a valid path, IsEmpty says so, and every operation on it either says so too or throws — it exists so that a VirtualPath field can be unset without being a lie.

Fields and properties (10)

  • public const char Separator

    The separator. There is exactly one, on every platform.

  • public static VirtualPath Root

    The root, /.

  • public string Value

    The normalised text. Empty for the default value.

  • public bool IsEmpty

    Whether this is the default, which is not a path.

  • public bool IsRoot

    Whether this is the root, /.

  • public VirtualPath Mount

    The mount this path belongs to — its first segment, as a path.

  • public VirtualPath Parent

    The containing directory, or the root for a top-level entry.

  • public ReadOnlySpan<char> FileName

    The last segment: the file or directory name.

  • public ReadOnlySpan<char> Extension

    The extension, including the leading dot, or empty if there is none.

  • public ReadOnlySpan<char> FileNameWithoutExtension

    The last segment without its extension.

Methods (16)

  • public VirtualPath(string path)

    Creates a path, normalising and validating it.

  • public static bool TryCreate(string? path, out VirtualPath result)

    Creates a path if it is valid.

  • public VirtualPath Combine(string relative)

    Appends a relative path.

  • public static VirtualPath operator /(VirtualPath left, string right)

    Appends a relative path.

  • public VirtualPath WithExtension(string extension)

    Replaces the extension.

  • public bool Contains(VirtualPath other)

    Whether is this path or is under it.

  • public VirtualPath RelativeTo(VirtualPath prefix)

    Removes a leading path, leaving what is below it, still rooted.

  • public VirtualPath.SegmentEnumerator EnumerateSegments()

    Walks the segments, without allocating a string for any of them.

  • public int CompareTo(VirtualPath other)

    Compares ordinally, which is the same order on every platform.

  • public override string ToString()

    Renders the path.

  • public string ToString(string? format, IFormatProvider? formatProvider)

    Renders the path.

  • public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

    Writes the path into a span.

  • public static bool operator <(VirtualPath left, VirtualPath right)

    Orders paths ordinally.

  • public static bool operator <=(VirtualPath left, VirtualPath right)

    Orders paths ordinally.

  • public static bool operator >(VirtualPath left, VirtualPath right)

    Orders paths ordinally.

  • public static bool operator >=(VirtualPath left, VirtualPath right)

    Orders paths ordinally.

Used by (83, showing 40)

  • BundleCacheVixen.Assets
  • BundleCacheTestsVixen.Assets.Tests
  • BundleOdbBackendVixen.Core.Serialization
  • CommitOnDisposeStreamVixen.Core.IO
  • ContentMountVixen.App.Hosting
  • ContentUpdateVixen.Assets
  • FileChangeVixen.Core.IO
  • FileChangeCoalescerVixen.Core.IO
  • FileChangeCoalescerTestsVixen.Core.IO.Tests
  • FileEntryVixen.Core.IO
  • FileOdbBackendVixen.Core.Serialization
  • FileProviderConformanceVixen.Core.IO.Tests
  • FileWatcherVixen.Core.IO
  • FileWatcherTestsVixen.Core.IO.Tests
  • HostLogVixen.App.Hosting
  • IFileProviderVixen.Core.IO
  • IFileWatcherVixen.Core.IO
  • LocalBundleSourceVixen.Assets
  • LooseContentSourceVixen.Assets
  • MemoryFileProviderVixen.Core.IO
  • MinimalProviderVixen.Core.IO.Tests
  • MountEntryVixen.Core.IO
  • MountPointsVixen.Core.IO
  • ObjectDatabaseTestsVixen.Core.Serialization.Tests
  • PendingVixen.Core.IO
  • PhysicalFileProviderVixen.Core.IO
  • PhysicalFileProviderTestsVixen.Core.IO.Tests
  • RemoteBundleSourceVixen.Assets
  • RemoteWorldVixen.Assets.Tests
  • SegmentEnumeratorVixen.Core.IO
  • StandardFileSystemHostTestsVixen.Platform.Tests
  • VirtualFileSystemVixen.Core.IO
  • VirtualFileSystemTestsVixen.Core.IO.Tests
  • VirtualPathTestsVixen.Core.IO.Tests
  • WebContentManifestVixen.Platform.Web.Tests
  • WebContentManifestEnumerationTestsVixen.Platform.Web.Tests
  • AnimationClipImporterTestsVixen.Editor.Assets.Tests
  • AudioImporterVixen.Editor.Assets
  • AudioImporterTestsVixen.Editor.Assets.Tests
  • ClipMetadataTestsVixen.Editor.Assets.Tests