/*
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.ComponentModel.Composition;
using System.Globalization;
using dnSpy.Contracts.Debugger.Evaluation;
using dnSpy.Contracts.Debugger.Text;
using dnSpy.Debugger.DotNet.Metadata;
namespace dnSpy.Contracts.Debugger.DotNet.Evaluation.Formatters {
///
/// Formats values, types, names. Use
/// to export an instance.
///
public abstract class DbgDotNetFormatter {
///
/// Formats an exception name
///
/// Evaluation context
/// Output
/// Exception id
public abstract void FormatExceptionName(DbgEvaluationContext context, IDbgTextWriter output, uint id);
///
/// Formats a stowed exception name
///
/// Evaluation context
/// Output
/// Stowed exception id
public abstract void FormatStowedExceptionName(DbgEvaluationContext context, IDbgTextWriter output, uint id);
///
/// Formats a return value name
///
/// Evaluation context
/// Output
/// Return value id
public abstract void FormatReturnValueName(DbgEvaluationContext context, IDbgTextWriter output, uint id);
///
/// Formats an object ID name
///
/// Evaluation context
/// Output
/// Object id
public abstract void FormatObjectIdName(DbgEvaluationContext context, IDbgTextWriter output, uint id);
///
/// Formats a value
///
/// Evaluation info
/// Output
/// Value to format
/// Options
/// Culture or null to use invariant culture
public abstract void FormatValue(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgDotNetValue value, DbgValueFormatterOptions options, CultureInfo? cultureInfo);
///
/// Formats a type
///
/// Evaluation info
/// Output
/// Type to format
/// Value or null
/// Options
/// Culture or null to use invariant culture
public abstract void FormatType(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DmdType type, DbgDotNetValue? value, DbgValueFormatterTypeOptions options, CultureInfo? cultureInfo);
///
/// Formats a stack frame
///
/// Evaluation info
/// Output
/// Stack frame options
/// Value option
/// Culture or null to use invariant culture
public abstract void FormatFrame(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgStackFrameFormatterOptions options, DbgValueFormatterOptions valueOptions, CultureInfo? cultureInfo);
}
/// Metadata
public interface IDbgDotNetFormatterMetadata {
/// See
string LanguageGuid { get; }
/// See
double Order { get; }
}
///
/// Exports a instance
///
[MetadataAttribute, AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class ExportDbgDotNetFormatterAttribute : ExportAttribute, IDbgDotNetFormatterMetadata {
///
/// Constructor
///
/// Language GUID, see
/// Order
public ExportDbgDotNetFormatterAttribute(string languageGuid, double order = double.MaxValue)
: base(typeof(DbgDotNetFormatter)) {
LanguageGuid = languageGuid ?? throw new ArgumentNullException(nameof(languageGuid));
Order = order;
}
///
/// Language GUID, see
///
public string LanguageGuid { get; }
///
/// Order
///
public double Order { get; }
}
}