Fork me on GitHub

File Paths

Motivation

The .Net framework uses simple strings to represent paths in the file system. For example File.Delete(string path). So do we in our code.

The problem is that we never know for sure whether it is an absolute or relative path. Or if it is even a path with a shortcut like %AppData%. We assign strings to strings and by making a wrong assumption, we introduced a defect.

The file path classes of Appccelerate help you to make your code cleaner by using strongly typed variables.

Absolute Path

The AbsolutePath represents an absolute path - a rooted path. It can be a file or folder path.

When instantiating an absolute path

the path is checked whether it is really an absolute path. In the error case, an ArgumentException is thrown.

An absolute path can be converted to a AbsoluteFilePath or AbsoluteFolderPath by using one of following methods on the AbsolutePath:

Absolute File Path

Represents an absolute file path.

It is only valid when the path is an absolute path and contains a filename.

Absolute Folder Path

Represents an absolute folder path.

Shortcut Path

Represents a path with a shortcut like %AppData%.

Checks whether there is an even number of % characters in the path.

Equality, HashCode, == and !=

All Appccelerate paths support the methods Equals, HashCode and the operators ==, !=.

Implicit Conversions

All Appccelerate paths can implicitly be casted to and from string.

That means you can assign paths from strings or pass paths to methods using strings (like the one of the .Net framework).

Different types of paths cannot be assigned to each other. To prevent for example assigning a folder path to a file path.