/*
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 dnlib.DotNet;
using dnSpy.Contracts.Text;
namespace dnSpy.Contracts.Decompiler {
///
/// A decompiler
///
public interface IDecompiler {
///
/// Gets the settings
///
DecompilerSettingsBase Settings { get; }
///
/// Gets the instance
///
MetadataTextColorProvider MetadataTextColorProvider { get; }
///
/// Gets the content type string
///
string ContentTypeString { get; }
///
/// Real name of the language, eg. "C#" if it's C#. See also .
/// It's used when the real language name must be shown to the user.
///
string GenericNameUI { get; }
///
/// Language name shown to the user, and can contain extra info eg. "C# XYZ", see also
/// .
///
string UniqueNameUI { get; }
///
/// Order of language when shown to the user, eg.
///
double OrderUI { get; }
///
/// Language guid, eg. , see also
///
Guid GenericGuid { get; }
///
/// Unique language guid, see also
///
Guid UniqueGuid { get; }
///
/// File extension, eg. .cs, can't be null
///
string FileExtension { get; }
///
/// Project file extension, eg. .csproj or null if it's not supported
///
string? ProjectFileExtension { get; }
///
/// Writes a type name
///
/// Output
/// Type
void WriteName(ITextColorWriter output, TypeDef type);
///
/// Writes a property name
///
/// Output
/// Type
/// true if it's an indexer
void WriteName(ITextColorWriter output, PropertyDef property, bool? isIndexer);
///
/// Writes a type name
///
/// Output
/// Type
/// true to include namespace
/// or null
void WriteType(ITextColorWriter output, ITypeDefOrRef? type, bool includeNamespace, ParamDef? pd = null);
///
/// Decompiles a method
///
/// Method
/// Output
/// Context
void Decompile(MethodDef method, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles a property
///
/// Property
/// Output
/// Context
void Decompile(PropertyDef property, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles a field
///
/// Field
/// Output
/// Context
void Decompile(FieldDef field, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles an event
///
/// Event
/// Output
/// Context
void Decompile(EventDef ev, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles a type
///
/// Type
/// Output
/// Context
void Decompile(TypeDef type, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles a namespace
///
/// Namespace
/// Types in namespace
/// Output
/// Context
void DecompileNamespace(string @namespace, IEnumerable types, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles an assembly
///
/// Assembly
/// Output
/// Context
void Decompile(AssemblyDef asm, IDecompilerOutput output, DecompilationContext ctx);
///
/// Decompiles a module
///
/// Module
/// Output
/// Context
void Decompile(ModuleDef mod, IDecompilerOutput output, DecompilationContext ctx);
///
/// Writes a tooltip
///
/// Output
/// Member
/// Type containing attributes, used to detect the dynamic types and out/ref params
void WriteToolTip(ITextColorWriter output, IMemberRef member, IHasCustomAttribute? typeAttributes);
///
/// Writes a tooltip
///
/// Output
/// Local or argument
void WriteToolTip(ITextColorWriter output, ISourceVariable variable);
///
/// Writes a namespace tooltip
///
/// Output
/// Namespace
void WriteNamespaceToolTip(ITextColorWriter output, string? @namespace);
///
/// Writes to
///
/// Output
/// Member
/// Flags
void Write(ITextColorWriter output, IMemberRef member, FormatterOptions flags);
///
/// Writes a comment prefix
///
/// Output
/// true to add a space before the comment prefix
void WriteCommentBegin(IDecompilerOutput output, bool addSpace);
///
/// Writes a comment suffix
///
/// Output
/// true to add a space before the comment suffix (if it's written)
void WriteCommentEnd(IDecompilerOutput output, bool addSpace);
///
/// Returns true if the member is visible. Can be used to hide compiler generated types, methods etc
///
/// Member
///
bool ShowMember(IMemberRef member);
///
/// Returns true if is supported and
/// can be called.
///
/// Decompilation type
///
bool CanDecompile(DecompilationType decompilationType);
///
/// Decompiles some data. Should only be called if
/// returns true
///
/// Decompilation type
/// Data, see
void Decompile(DecompilationType decompilationType, object data);
}
///
/// Extension methods
///
public static class DecompilerExtensionMethods {
///
/// Writes a comment and a new line
///
/// This
/// Output
/// Comment
public static void WriteCommentLine(this IDecompiler self, IDecompilerOutput output, string comment) {
self.WriteCommentBegin(output, true);
output.Write(comment, BoxedTextColor.Comment);
self.WriteCommentEnd(output, true);
output.WriteLine();
}
}
}