Browse Source

Fix #628: Add option to display metadata token in 10-based or hex format.

pull/1360/head
Siegfried Pammer 8 years ago
parent
commit
fbfcd6f72a
  1. 11
      ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs
  2. 5
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  3. 42
      ILSpy/ExtensionMethods.cs
  4. 1
      ILSpy/Languages/ILLanguage.cs
  5. 16
      ILSpy/Options/DisplaySettings.cs
  6. 1
      ILSpy/Options/DisplaySettingsPanel.xaml
  7. 6
      ILSpy/Options/DisplaySettingsPanel.xaml.cs

11
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

@ -52,6 +52,11 @@ namespace ICSharpCode.Decompiler.Disassembler
/// </summary> /// </summary>
public bool ShowMetadataTokens { get; set; } public bool ShowMetadataTokens { get; set; }
/// <summary>
/// Show metadata tokens for instructions with token operands in base 10.
/// </summary>
public bool ShowMetadataTokensInBase10 { get; set; }
/// <summary> /// <summary>
/// Optional provider for sequence points. /// Optional provider for sequence points.
/// </summary> /// </summary>
@ -453,7 +458,11 @@ namespace ICSharpCode.Decompiler.Disassembler
if (spaceBefore) { if (spaceBefore) {
output.Write(' '); output.Write(' ');
} }
output.Write("/* {0:X8} */", metadataToken); if (ShowMetadataTokensInBase10) {
output.Write("/* {0} */", metadataToken);
} else {
output.Write("/* {0:X8} */", metadataToken);
}
} }
} }
} }

5
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -56,6 +56,11 @@ namespace ICSharpCode.Decompiler.Disassembler
set => methodBodyDisassembler.ShowMetadataTokens = value; set => methodBodyDisassembler.ShowMetadataTokens = value;
} }
public bool ShowMetadataTokensInBase10 {
get => methodBodyDisassembler.ShowMetadataTokensInBase10;
set => methodBodyDisassembler.ShowMetadataTokensInBase10 = value;
}
public IDebugInfoProvider DebugInfo { public IDebugInfoProvider DebugInfo {
get => methodBodyDisassembler.DebugInfo; get => methodBodyDisassembler.DebugInfo;
set => methodBodyDisassembler.DebugInfo = value; set => methodBodyDisassembler.DebugInfo = value;

42
ILSpy/ExtensionMethods.cs

@ -101,52 +101,40 @@ namespace ICSharpCode.ILSpy
return false; return false;
} }
*/ */
public static string ToSuffixString(this System.Reflection.Metadata.EntityHandle token) public static string ToSuffixString(this System.Reflection.Metadata.EntityHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens)
return string.Empty; return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8"); int token = System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(handle);
if (DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10)
return " @" + token;
return " @" + token.ToString("x8");
} }
public static string ToSuffixString(this System.Reflection.Metadata.MethodDefinitionHandle token) public static string ToSuffixString(this System.Reflection.Metadata.MethodDefinitionHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) return ToSuffixString((System.Reflection.Metadata.EntityHandle)handle);
return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8");
} }
public static string ToSuffixString(this System.Reflection.Metadata.PropertyDefinitionHandle token) public static string ToSuffixString(this System.Reflection.Metadata.PropertyDefinitionHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) return ToSuffixString((System.Reflection.Metadata.EntityHandle)handle);
return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8");
} }
public static string ToSuffixString(this System.Reflection.Metadata.EventDefinitionHandle token) public static string ToSuffixString(this System.Reflection.Metadata.EventDefinitionHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) return ToSuffixString((System.Reflection.Metadata.EntityHandle)handle);
return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8");
} }
public static string ToSuffixString(this System.Reflection.Metadata.FieldDefinitionHandle token) public static string ToSuffixString(this System.Reflection.Metadata.FieldDefinitionHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) return ToSuffixString((System.Reflection.Metadata.EntityHandle)handle);
return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8");
} }
public static string ToSuffixString(this System.Reflection.Metadata.TypeDefinitionHandle token) public static string ToSuffixString(this System.Reflection.Metadata.TypeDefinitionHandle handle)
{ {
if (!DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens) return ToSuffixString((System.Reflection.Metadata.EntityHandle)handle);
return string.Empty;
return " @" + System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(token).ToString("x8");
} }
/// <summary> /// <summary>

1
ILSpy/Languages/ILLanguage.cs

@ -56,6 +56,7 @@ namespace ICSharpCode.ILSpy
DetectControlStructure = detectControlStructure, DetectControlStructure = detectControlStructure,
ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo, ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo,
ShowMetadataTokens = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens, ShowMetadataTokens = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens,
ShowMetadataTokensInBase10 = Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10,
ExpandMemberDefinitions = options.DecompilerSettings.ExpandMemberDefinitions ExpandMemberDefinitions = options.DecompilerSettings.ExpandMemberDefinitions
}; };
} }

16
ILSpy/Options/DisplaySettings.cs

@ -83,8 +83,7 @@ namespace ICSharpCode.ILSpy.Options
bool showMetadataTokens; bool showMetadataTokens;
public bool ShowMetadataTokens public bool ShowMetadataTokens {
{
get { return showMetadataTokens; } get { return showMetadataTokens; }
set { set {
if (showMetadataTokens != value) { if (showMetadataTokens != value) {
@ -94,6 +93,18 @@ namespace ICSharpCode.ILSpy.Options
} }
} }
bool showMetadataTokensInBase10;
public bool ShowMetadataTokensInBase10 {
get { return showMetadataTokensInBase10; }
set {
if (showMetadataTokensInBase10 != value) {
showMetadataTokensInBase10 = value;
OnPropertyChanged();
}
}
}
bool enableWordWrap; bool enableWordWrap;
public bool EnableWordWrap public bool EnableWordWrap
@ -126,6 +137,7 @@ namespace ICSharpCode.ILSpy.Options
this.SelectedFontSize = s.selectedFontSize; this.SelectedFontSize = s.selectedFontSize;
this.ShowLineNumbers = s.showLineNumbers; this.ShowLineNumbers = s.showLineNumbers;
this.ShowMetadataTokens = s.showMetadataTokens; this.ShowMetadataTokens = s.showMetadataTokens;
this.ShowMetadataTokensInBase10 = s.showMetadataTokensInBase10;
this.EnableWordWrap = s.enableWordWrap; this.EnableWordWrap = s.enableWordWrap;
this.SortResults = s.sortResults; this.SortResults = s.sortResults;
} }

1
ILSpy/Options/DisplaySettingsPanel.xaml

@ -61,6 +61,7 @@
<StackPanel Margin="3"> <StackPanel Margin="3">
<CheckBox IsChecked="{Binding ShowLineNumbers}">Show line numbers</CheckBox> <CheckBox IsChecked="{Binding ShowLineNumbers}">Show line numbers</CheckBox>
<CheckBox IsChecked="{Binding ShowMetadataTokens}">Show metadata tokens</CheckBox> <CheckBox IsChecked="{Binding ShowMetadataTokens}">Show metadata tokens</CheckBox>
<CheckBox IsChecked="{Binding ShowMetadataTokensInBase10}">Show metadata tokens in base 10</CheckBox>
<CheckBox IsChecked="{Binding EnableWordWrap}">Enable word wrap</CheckBox> <CheckBox IsChecked="{Binding EnableWordWrap}">Enable word wrap</CheckBox>
<CheckBox IsChecked="{Binding SortResults}">Sort results by fitness</CheckBox> <CheckBox IsChecked="{Binding SortResults}">Sort results by fitness</CheckBox>
</StackPanel> </StackPanel>

6
ILSpy/Options/DisplaySettingsPanel.xaml.cs

@ -100,8 +100,9 @@ namespace ICSharpCode.ILSpy.Options
s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas"); s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas");
s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3; s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3;
s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false; s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false;
s.ShowMetadataTokens = (bool?) e.Attribute("ShowMetadataTokens") ?? false; s.ShowMetadataTokens = (bool?)e.Attribute("ShowMetadataTokens") ?? false;
s.EnableWordWrap = (bool?)e.Attribute("EnableWordWrap") ?? false; s.ShowMetadataTokensInBase10 = (bool?)e.Attribute("ShowMetadataTokensInBase10") ?? false;
s.EnableWordWrap = (bool?)e.Attribute("EnableWordWrap") ?? false;
s.SortResults = (bool?)e.Attribute("SortResults") ?? true; s.SortResults = (bool?)e.Attribute("SortResults") ?? true;
return s; return s;
@ -116,6 +117,7 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("FontSize", s.SelectedFontSize); section.SetAttributeValue("FontSize", s.SelectedFontSize);
section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers); section.SetAttributeValue("ShowLineNumbers", s.ShowLineNumbers);
section.SetAttributeValue("ShowMetadataTokens", s.ShowMetadataTokens); section.SetAttributeValue("ShowMetadataTokens", s.ShowMetadataTokens);
section.SetAttributeValue("ShowMetadataTokensInBase10", s.ShowMetadataTokensInBase10);
section.SetAttributeValue("EnableWordWrap", s.EnableWordWrap); section.SetAttributeValue("EnableWordWrap", s.EnableWordWrap);
section.SetAttributeValue("SortResults", s.SortResults); section.SetAttributeValue("SortResults", s.SortResults);

Loading…
Cancel
Save