/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.IO; namespace dnSpy.Contracts.Documents { /// /// Compares filenames /// public sealed class FilenameKey : IDsDocumentNameKey, IEquatable { readonly string filename; /// /// Constructor /// /// Filename public FilenameKey(string filename) => this.filename = GetFullPath(filename); FilenameKey(string filename, bool dummy) => this.filename = filename; // PERF: Path.GetFullPath() is slow so if we know that FilenameKey.GetFullPath() == filename, use this method instead internal static FilenameKey CreateFullPath(string filename) => new FilenameKey(filename, false); static string GetFullPath(string filename) { try { // Prevent slow exceptions if (string.IsNullOrEmpty(filename)) return filename; return Path.GetFullPath(filename); } catch { } return filename; } /// /// Equals() /// /// Other instance /// public bool Equals(FilenameKey? other) => other is not null && StringComparer.OrdinalIgnoreCase.Equals(filename, other.filename); /// /// Equals() /// /// Other instance /// public override bool Equals(object? obj) => Equals(obj as FilenameKey); /// /// GetHashCode() /// /// public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(filename); /// /// ToString() /// /// public override string ToString() => filename; } }