/* 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.Diagnostics; namespace dnSpy.Contracts.Documents { /// /// Document info /// public readonly struct DsDocumentInfo { /// /// Name, eg. filename if is or /// (can be empty) /// public string Name => name ?? string.Empty; readonly string name; /// /// Optional data used by some types /// public object? Data { get; } /// /// Document type, eg. /// public Guid Type { get; } /// /// Creates a used by files on disk /// /// Filename /// public static DsDocumentInfo CreateDocument(string filename) => new DsDocumentInfo(filename, DocumentConstants.DOCUMENTTYPE_FILE); /// /// Creates a used by files in the GAC /// /// Full name of assembly /// public static DsDocumentInfo CreateGacDocument(string asmFullName) => new DsDocumentInfo(asmFullName, DocumentConstants.DOCUMENTTYPE_GAC); /// /// Creates a used by reference assemblies /// /// Full name of assembly /// Path to the reference assembly. It's used if it's not found /// in the GAC. /// public static DsDocumentInfo CreateReferenceAssembly(string asmFullName, string refFilePath) { Debug.Assert(!refFilePath.Contains(DocumentConstants.REFERENCE_ASSEMBLY_SEPARATOR)); return new DsDocumentInfo(asmFullName + DocumentConstants.REFERENCE_ASSEMBLY_SEPARATOR + refFilePath, DocumentConstants.DOCUMENTTYPE_REFASM); } /// /// Creates a used by in-memory files /// /// Creates the file data /// Filename or null/empty string if it's unknown /// public static DsDocumentInfo CreateInMemory(Func<(byte[]? filedata, bool isFileLayout)> getFileData, string? filename) { if (getFileData is null) throw new ArgumentNullException(nameof(getFileData)); return new DsDocumentInfo(filename ?? string.Empty, DocumentConstants.DOCUMENTTYPE_INMEMORY, getFileData); } /// /// Constructor /// /// Name, see /// Type, see public DsDocumentInfo(string name, Guid type) { this.name = name ?? string.Empty; Type = type; Data = null; } /// /// Constructor /// /// Name, see /// Type, see /// Data, see public DsDocumentInfo(string name, Guid type, object? data) { this.name = name ?? string.Empty; Type = type; Data = data; } /// /// ToString() /// /// public override string ToString() => $"{Name} {Type}"; } }