mirror of
https://github.com/icsharpcode/ILSpy.git
synced 2026-10-12 11:09:54 +00:00
The Avalonia port had placed the UI app in an ILSpy.* namespace tree, while the csproj RootNamespace and every prior release (through 10.1) use ICSharpCode.ILSpy.*. Restoring the historical namespace reduces the public API diff against release/10.1 for plugin authors and removes the shadowing that forced global:: qualifiers in the test project. The Images class and AccessOverlayIcon enum move back into the root namespace (as in 10.1), since an ICSharpCode.ILSpy.Images namespace would shadow the Images class for all code inside ICSharpCode.ILSpy. Assisted-by: Claude:claude-fable-5:Claude Code
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
|
|
|
using System.Composition;
|
|
using System.Reflection.Metadata;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using ICSharpCode.Decompiler;
|
|
using ICSharpCode.Decompiler.TypeSystem;
|
|
|
|
using ICSharpCode.ILSpy;
|
|
using ICSharpCode.ILSpy.Languages;
|
|
using ICSharpCode.ILSpy.TextView;
|
|
|
|
namespace TestPlugin
|
|
{
|
|
/// <summary>
|
|
/// Adds a new language to the decompiler.
|
|
/// </summary>
|
|
[Export(typeof(Language))]
|
|
[Shared]
|
|
public class CustomLanguage : Language
|
|
{
|
|
public override string Name {
|
|
get {
|
|
return "Custom";
|
|
}
|
|
}
|
|
|
|
public override string FileExtension {
|
|
get {
|
|
// used in 'Save As' dialog
|
|
return ".txt";
|
|
}
|
|
}
|
|
|
|
// There are several methods available to override; in this sample, we deal with methods only
|
|
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
|
|
{
|
|
var module = ((MetadataModule)method.ParentModule!).MetadataFile;
|
|
var methodDef = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken);
|
|
if (methodDef.HasBody())
|
|
{
|
|
var methodBody = module.GetMethodBody(methodDef.RelativeVirtualAddress);
|
|
output.WriteLine("Size of method: {0} bytes", methodBody.GetCodeSize());
|
|
|
|
if (output is ISmartTextOutput smartOutput)
|
|
{
|
|
// when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons:
|
|
smartOutput.AddButton(null, "Click me!", (sender, e) => {
|
|
if (sender is Button button)
|
|
button.Content = "I was clicked!";
|
|
});
|
|
smartOutput.WriteLine();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|