PathComponents Structure

Representation of platform-dependent paths in platform-independent manner as a collection of path components exposed through IEnumerable and array access. Use Make(String) to create an instance.

Definition

Namespace: Quine.Schemas.Core
Assembly: Quine.Schemas.Core (in Quine.Schemas.Core.dll) Version: 1.0.0+0ea0706914ee4edf2b0ed66bec3ab4d062a43b68
C#
[DataContractAttribute(Namespace = "http://schemas.quine.no/core/v3_0.xsd")]
public struct PathComponents : IEnumerable<string>, 
	IEnumerable, IEquatable<PathComponents>, IContentAddressable
Inheritance
Object    ValueType    PathComponents
Implements
IContentAddressable, IEnumerableString, IEnumerable, IEquatablePathComponents

Remarks

If IsAbsolute is true, the 0th component of the path is the "root component", otherwise the whole path is relative. Supports mixed-separator paths on input; the separator is internally replaced with SeparatorChar . Correctly parses Windows and Unix paths on both platforms.

A path MUST not contain empty components, with the exception of Unix absolute paths where the root component is an empty string. (In string form, this means that a path ending with / or having // in the middle is invalid.) Supported path patterns are the following:

  • a/b/c is a relative path.
  • /a/b/c is an absolute UNIX path; only "" is the root component.
  • X:/a/b/c is an absolute Windows path with "X:" as the root component. The slash after colon is obligatory; otherwise the path is drive-relative.
  • //server/share/a/b/c is a Windows SMB-path. //server/share is the root component, the rest are relative components.

PathFormatException is thrown when invalid paths are given or internal variants violated.

This class is needed because Path class behaves differently on different platforms.

Properties

IsEmpty True if this is an empty PathComponents object (Empty). NB! This will return true also for a default instance.
IsNull True only for a default instance (i.e., Empty instance will return false).
Item Indexer.
Length Number of components in this path.
NativeString Returns a string representation of this using the platform's native character separator.

Methods

Append Appends components to the end of this.
Equals(Object)Indicates whether this instance and a specified object are equal.
(Overrides ValueTypeEquals(Object))
Equals(PathComponents) Two instances are equal if they are component-wise equal AND both have the same value of IsAbsolute property.
GetEnumeratorReturns an enumerator that iterates through the collection.
GetHashCodeReturns the hash code for this instance.
(Overrides ValueTypeGetHashCode)
IsPrefixOf Check whether this path is a prefix of other. A path is a prefix of itself.
IsSuffixOf Check whether this path is a suffix of other. A path is a suffix of itself.
Join Returns the concatenation of the given components. Empty components, except the 1st one, are removed.
Make Creates an instance.
Prepend Returns new object with the given components prepended to this object.
RemovePrefix(Int32) Remove the given number of components from this path.
RemovePrefix(PathComponents) Remove a path prefix from this path.
RemoveSuffix(Int32) Remove the given number of components from this path.
RemoveSuffix(PathComponents) Remove a path suffix from this path
ReplaceComponent Replaces the component at componentIndex with newValue

Operators

Fields

Empty Unique instance of an empty PathComponents object: it has zero components and is not absolute. An empty PathComponents object cannot be instantiated in any other way. NB! default instance is regrettably NOT equal to Empty.
ForbiddenChars A set of characters that must not occur in either native file names or path names in a cross-platform application. '\' is also included; it may possibly be a valid filename char on unix, but we can't allow it in xplatform app.
IsAbsolute True if this is an absolute path.
IsWindows True if we're running on Windows.
NormalizedString Normalized string for serialization; uses '/' as separator character.
SeparatorChar The / character is internally used to separate individual components.

See Also