/*
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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using dnSpy.Contracts.Decompiler;
using dnSpy.Contracts.Text;
namespace dnSpy.Contracts.Documents.Tabs.DocViewer {
///
/// content
///
public sealed class DocumentViewerContent {
///
/// Gets the text
///
public string Text { get; }
///
/// Gets the colors
///
internal CachedTextColorsCollection ColorCollection { get; }
///
/// Gets the references
///
public SpanDataCollection ReferenceCollection { get; }
///
/// Gets the method debug info collection
///
public IReadOnlyList MethodDebugInfos { get; }
readonly Dictionary customDataDict;
///
/// Constructor
///
/// Text
/// Colors
/// References
/// Custom data dictionary
internal DocumentViewerContent(string text, CachedTextColorsCollection colorCollection, SpanDataCollection referenceCollection, Dictionary customDataDict) {
if (colorCollection is null)
throw new ArgumentNullException(nameof(colorCollection));
colorCollection.Freeze();
Text = text ?? throw new ArgumentNullException(nameof(text));
ColorCollection = colorCollection;
ReferenceCollection = referenceCollection ?? throw new ArgumentNullException(nameof(referenceCollection));
this.customDataDict = customDataDict ?? throw new ArgumentNullException(nameof(customDataDict));
MethodDebugInfos = (IReadOnlyList?)GetCustomData>(DocumentViewerContentDataIds.DebugInfo) ?? Array.Empty();
}
///
/// Gets custom data. Returns false if it doesn't exist.
///
/// Type of data
/// Key, eg.,
/// Updated with data
///
public bool TryGetCustomData(string id, out TData data) {
if (!customDataDict.TryGetValue(id, out var obj)) {
data = default!;
return false;
}
data = (TData)obj;
return true;
}
///
/// Gets custom data
///
/// Type of data
/// Key, eg.,
///
[return: MaybeNull]
public TData GetCustomData(string id) {
if (!customDataDict.TryGetValue(id, out var obj))
return default!;
return (TData)obj;
}
}
}