Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
UDirectory.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.ComponentModel;
5 
6 namespace SiliconStudio.Core.IO
7 {
8  /// <summary>
9  /// Defines a normalized directory path. See <see cref="UPath"/> for details. This class cannot be inherited.
10  /// </summary>
11  [DataContract("UDirectory")]
12  [TypeConverter(typeof(UDirectoryTypeConverter))]
13  public sealed class UDirectory : UPath
14  {
15  /// <summary>
16  /// An empty directory.
17  /// </summary>
18  public static readonly UDirectory Empty = new UDirectory(string.Empty);
19 
20  /// <summary>
21  /// A this '.' directory.
22  /// </summary>
23  public static readonly UDirectory This = new UDirectory(".");
24 
25  /// <summary>
26  /// Initializes a new instance of the <see cref="UDirectory"/> class.
27  /// </summary>
28  /// <param name="directoryPath">The directory path.</param>
29  public UDirectory(string directoryPath) : base(directoryPath, true)
30  {
31  }
32 
33  internal UDirectory(string fullPath, StringSpan driveSpan, StringSpan directorySpan) : base(fullPath, driveSpan, directorySpan)
34  {
35  }
36 
37  /// <summary>
38  /// Makes this instance relative to the specified anchor directory.
39  /// </summary>
40  /// <param name="anchorDirectory">The anchor directory.</param>
41  /// <returns>A relative path of this instance to the anchor directory.</returns>
42  public new UDirectory MakeRelative(UDirectory anchorDirectory)
43  {
44  return (UDirectory)base.MakeRelative(anchorDirectory);
45  }
46 
47  /// <summary>
48  /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="UPath"/>.
49  /// </summary>
50  /// <param name="fullPath">The full path.</param>
51  /// <returns>The result of the conversion.</returns>
52  public static implicit operator UDirectory(string fullPath)
53  {
54  return fullPath != null ? new UDirectory(fullPath) : null;
55  }
56 
57  /// <summary>
58  /// Determines whether this directory contains the specified path.
59  /// </summary>
60  /// <param name="path">The path.</param>
61  /// <returns><c>true</c> if this directory contains the specified path; otherwise, <c>false</c>.</returns>
62  public bool Contains(UPath path)
63  {
64  if (path == null) throw new ArgumentNullException("path");
65  if (FullPath == null) return false;
66  if (path.FullPath == null) return false;
67 
68  return path.FullPath.StartsWith(FullPath, StringComparison.OrdinalIgnoreCase) && path.FullPath.Length > FullPath.Length && path.FullPath[FullPath.Length] == DirectorySeparatorChar;
69  }
70  }
71 }
new UDirectory MakeRelative(UDirectory anchorDirectory)
Makes this instance relative to the specified anchor directory.
Definition: UDirectory.cs:42
string FullPath
Gets the full path ((drive?)(directory?/)(name.ext?)). An empty path is an empty string.
Definition: UPath.cs:118
UDirectory(string directoryPath)
Initializes a new instance of the UDirectory class.
Definition: UDirectory.cs:29
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
Definition: UDirectory.cs:13
Base class that describes a uniform path and provides method to manipulate them. Concrete class are U...
Definition: UPath.cs:21
delegate object TypeConverter(object arg)
bool Contains(UPath path)
Determines whether this directory contains the specified path.
Definition: UDirectory.cs:62
A region of character in a string.
Definition: StringSpan.cs:12