📄 reflectionildasmview.cs
字号:
// ReflectionILDasmView.cs
// Copyright (C) 2001 Mike Krueger
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Reflection;
using System.Reflection.Emit;
using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Internal.Undo;
using SharpDevelop.Gui.Window;
namespace SharpDevelop.Gui.Edit.Reflection {
public class ReflectionILDasmView : UserControl
{
RichTextBox tb = new RichTextBox();
ReflectionTree tree;
public ReflectionILDasmView(MainWindow mainwindow, ReflectionTree tree)
{
this.tree = tree;
Dock = DockStyle.Fill;
tb.Font = SharpDevelop.Internal.Text.FontContainer.DefaultFont;
tb.Dock = DockStyle.Fill;
tb.ScrollBars = RichTextBoxScrollBars.Both;
tb.WordWrap = false;
tb.ReadOnly = true;
Controls.Add(tb);
tree.AfterSelect += new TreeViewEventHandler(SelectNode);
}
void SelectNode(object sender, TreeViewEventArgs e)
{
ReflectionNode node = (ReflectionNode)e.Node;
Assembly assembly = null;
string item = " /item=";
if (node.Attribute is Assembly) {
assembly = (Assembly)node.Attribute;
} else
if (node.Attribute is Type) {
Type type = (Type)node.Attribute;
item += type.FullName;
assembly = type.Module.Assembly;
} else
if (node.Attribute is MethodBase) {
MethodBase method = (MethodBase) node.Attribute;
item += method.DeclaringType.FullName + "::" + method.Name;
assembly = method.DeclaringType.Module.Assembly;
} else {
tb.Text = "<NO ILDASM VIEW AVAIBLE>";
return;
}
tb.Text = GetILDASMOutput(assembly, item).Replace("\n", "\r\n");
}
private string GetILDASMOutput(Assembly assembly, string item)
{
string args = assembly.Location + item + " /NOBAR /TEXT";
ProcessStartInfo psi = new ProcessStartInfo("ildasm.exe", args);
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
Process process = Process.Start(psi);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
int cutpos = output.IndexOf(".namespace");
if (cutpos != -1)
return output.Substring(cutpos);
cutpos = output.IndexOf(".class");
if (cutpos != -1)
return output.Substring(cutpos);
cutpos = output.IndexOf(".method");
if (cutpos != -1)
return output.Substring(cutpos);
return output;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -