# VirtualPath record struct

> A path inside an IFileSource: relative to the source's root, with forward slashes, no leading slash and no . or ... It can't name a drive or leave its tree, so a path read from a game's files is safe to follow. It's a small value type, and a string converts to one implicitly, so "id1/PAK0.PAK" works wherever a path is asked for.

Namespace `EvilEngine.Mounts`, assembly `EvilEngine.Mounts`. Engine commit 4ff877b1.

```csharp
public readonly record struct VirtualPath : IComparable<VirtualPath>
```

A path inside an [IFileSource](/docs/api/ifilesource): relative to the source's root, with forward slashes, no leading slash and no `.` or `..`. It can't name a drive or leave its tree, so a path read from a game's files is safe to follow. It's a small value type, and a string converts to one implicitly, so `"id1/PAK0.PAK"` works wherever a path is asked for.

A path keeps the case it was written in. Whether two paths are the same file depends on the source's `CaseRule`, so compare them through a [Comparer](#comparer), never by their text alone.

## Members

### Separator (field)

```csharp
public const char Separator = '/'
```

`/`.

### Root (property)

```csharp
public static VirtualPath Root { get; }
```

The source's root, the empty path. It's also `default`.

### Value (property)

```csharp
public string Value { get; }
```

The path as text, empty for [Root](#root).

### IsRoot (property)

```csharp
public bool IsRoot { get; }
```

Whether this is [Root](#root).

### Name (property)

```csharp
public string Name { get; }
```

The last segment, as in `e1m1.bsp` for `id1/maps/e1m1.bsp`.

### Extension (property)

```csharp
public string Extension { get; }
```

The text after the last `.` in [Name](#name), without the dot, or empty when there's none. A name starting with its only dot, like `.gitignore`, has none.

### Parent (property)

```csharp
public VirtualPath Parent { get; }
```

The folder holding this path, [Root](#root) for a path at the top.

### WithoutExtension (property)

```csharp
public VirtualPath WithoutExtension { get; }
```

The path with its [Extension](#extension) and its dot taken off.

### CompareTo (method)

```csharp
public int CompareTo(VirtualPath other)
```

Orders paths by their text, ordinally, whatever the case rule.

### Parse (method)

```csharp
public static VirtualPath Parse(string path)
```

Makes a path from text. Backslashes and doubled slashes are cleaned up and `.` segments dropped, so `.\maps\\e1m1.bsp` makes `maps/e1m1.bsp`. Throws `ArgumentException` when a segment is `..` or holds a `:` or a null character.

### TryParse (method)

```csharp
public static bool TryParse(string path, out VirtualPath result)
```

[Parse](#parse), returning `false` rather than throwing.

### Join (method)

```csharp
public VirtualPath Join(string relative)
```

```csharp
public VirtualPath Join(VirtualPath relative)
```

Appends a relative path, as in `"id1".Join("maps/e1m1.bsp")`. Joining text parses it first, so it throws as [Parse](#parse) does.

### TryRelativeTo (method)

```csharp
public bool TryRelativeTo(VirtualPath directory, CaseRule caseRule, out VirtualPath relative)
```

Gets this path relative to `directory`, under a case rule, or returns `false` when it isn't inside it. Everything is inside [Root](#root).

### IsUnder (method)

```csharp
public bool IsUnder(VirtualPath directory, CaseRule caseRule, bool recursive)
```

Whether this path is inside `directory` under a case rule: anywhere beneath it with `recursive`, or directly in it without.

### Comparer (method)

```csharp
public static StringComparer Comparer(CaseRule caseRule)
```

A `StringComparer` for paths' [Value](#value)s under a case rule, for dictionaries and sets keyed by path. The `Equals` overload that takes a case rule compares two paths the same way.

### Comparison (method)

```csharp
public static StringComparison Comparison(CaseRule caseRule)
```

The `StringComparison` for a case rule, for comparing paths' text yourself.
