diff --git a/StabilityMatrix.Core/Models/FileInterfaces/FileSystemPath.cs b/StabilityMatrix.Core/Models/FileInterfaces/FileSystemPath.cs index e9d22fa2..8fc04491 100644 --- a/StabilityMatrix.Core/Models/FileInterfaces/FileSystemPath.cs +++ b/StabilityMatrix.Core/Models/FileInterfaces/FileSystemPath.cs @@ -1,6 +1,6 @@ namespace StabilityMatrix.Core.Models.FileInterfaces; -public class FileSystemPath : IEquatable, IEquatable +public class FileSystemPath : IEquatable, IEquatable, IFormattable { public string FullPath { get; } @@ -8,27 +8,42 @@ public class FileSystemPath : IEquatable, IEquatable { FullPath = path; } - - protected FileSystemPath(FileSystemPath path) : this(path.FullPath) + + protected FileSystemPath(FileSystemPath path) + : this(path.FullPath) { } + + protected FileSystemPath(params string[] paths) + : this(Path.Combine(paths)) { } + + public override string ToString() { + return FullPath; } - protected FileSystemPath(params string[] paths) : this(Path.Combine(paths)) + /// + string IFormattable.ToString(string? format, IFormatProvider? formatProvider) { + return ToString(format, formatProvider); } - - public override string ToString() + + /// + /// Overridable IFormattable.ToString method. + /// By default, returns . + /// + protected virtual string ToString(string? format, IFormatProvider? formatProvider) { return FullPath; } public bool Equals(FileSystemPath? other) { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; + if (ReferenceEquals(null, other)) + return false; + if (ReferenceEquals(this, other)) + return true; return FullPath == other.FullPath; } - + public bool Equals(string? other) { return string.Equals(FullPath, other); @@ -48,8 +63,9 @@ public class FileSystemPath : IEquatable, IEquatable { return FullPath.GetHashCode(); } - + // Implicit conversions to and from string public static implicit operator string(FileSystemPath path) => path.FullPath; + public static implicit operator FileSystemPath(string path) => new(path); }