// dnlib: See LICENSE.txt for more info
using System;
using System.Collections.Generic;
using System.Diagnostics;
using dnlib.DotNet.Pdb.Symbols;
namespace dnlib.DotNet.Pdb {
///
/// A PDB document
///
[DebuggerDisplay("{Url}")]
public sealed class PdbDocument : IHasCustomDebugInformation {
///
/// Gets/sets the document URL
///
public string Url { get; set; }
///
/// Gets/sets the language GUID. See
///
public Guid Language { get; set; }
///
/// Gets/sets the language vendor GUID. See
///
public Guid LanguageVendor { get; set; }
///
/// Gets/sets the document type GUID. See
///
public Guid DocumentType { get; set; }
///
/// Gets/sets the checksum algorithm ID. See
///
public Guid CheckSumAlgorithmId { get; set; }
///
/// Gets/sets the checksum
///
public byte[] CheckSum { get; set; }
///
public int HasCustomDebugInformationTag => 22;
///
public bool HasCustomDebugInfos => CustomDebugInfos.Count > 0;
///
/// Gets all custom debug infos
///
public IList CustomDebugInfos => customDebugInfos;
IList customDebugInfos;
///
/// Gets the Metadata token of the document if available.
///
public MDToken? MDToken { get; internal set; }
///
/// Default constructor
///
public PdbDocument() {
}
///
/// Constructor
///
/// A instance
public PdbDocument(SymbolDocument symDoc) : this(symDoc, partial: false) {
}
PdbDocument(SymbolDocument symDoc, bool partial) {
if (symDoc is null)
throw new ArgumentNullException(nameof(symDoc));
Url = symDoc.URL;
if (!partial)
Initialize(symDoc);
}
internal static PdbDocument CreatePartialForCompare(SymbolDocument symDoc) =>
new PdbDocument(symDoc, partial: true);
internal void Initialize(SymbolDocument symDoc) {
Language = symDoc.Language;
LanguageVendor = symDoc.LanguageVendor;
DocumentType = symDoc.DocumentType;
CheckSumAlgorithmId = symDoc.CheckSumAlgorithmId;
CheckSum = symDoc.CheckSum;
customDebugInfos = new List();
foreach (var cdi in symDoc.CustomDebugInfos)
customDebugInfos.Add(cdi);
MDToken = symDoc.MDToken;
}
///
/// Constructor
///
/// Document URL
/// Language. See
/// Language vendor. See
/// Document type. See
/// Checksum algorithm ID. See
/// Checksum
public PdbDocument(string url, Guid language, Guid languageVendor, Guid documentType, Guid checkSumAlgorithmId, byte[] checkSum) {
Url = url;
Language = language;
LanguageVendor = languageVendor;
DocumentType = documentType;
CheckSumAlgorithmId = checkSumAlgorithmId;
CheckSum = checkSum;
}
///
public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Url ?? string.Empty);
///
public override bool Equals(object obj) {
var other = obj as PdbDocument;
if (other is null)
return false;
return StringComparer.OrdinalIgnoreCase.Equals(Url ?? string.Empty, other.Url ?? string.Empty);
}
}
}