Browse Source

Hide compiler-generated enumerator classes when "yield return" decompilation is enabled.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
69cad52cb4
  1. 32
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ILSpy/CSharpLanguage.cs
  3. 2
      ILSpy/DecompilationOptions.cs
  4. 10
      ILSpy/DecompilerSettingsPanel.xaml.cs
  5. 11
      ILSpy/MainWindow.xaml.cs
  6. 4
      ILSpy/OptionsDialog.xaml.cs

32
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -33,19 +33,27 @@ namespace ICSharpCode.Decompiler.Ast
this.context = context;
}
public static bool MemberIsHidden(MemberReference member)
public static bool MemberIsHidden(MemberReference member, DecompilerSettings settings)
{
MethodDefinition method = member as MethodDefinition;
if (method != null && (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn))
return true;
if (method != null && method.Name.StartsWith("<", StringComparison.Ordinal) && method.IsCompilerGenerated())
return true;
if (method != null) {
if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn)
return true;
if (settings.AnonymousMethods && method.Name.StartsWith("<", StringComparison.Ordinal) && method.IsCompilerGenerated())
return true;
}
TypeDefinition type = member as TypeDefinition;
if (type != null && type.DeclaringType != null && type.Name.StartsWith("<>c__DisplayClass", StringComparison.Ordinal) && type.IsCompilerGenerated())
return true;
if (type != null && type.DeclaringType != null) {
if (settings.AnonymousMethods && type.Name.StartsWith("<>c__DisplayClass", StringComparison.Ordinal) && type.IsCompilerGenerated())
return true;
if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type))
return true;
}
FieldDefinition field = member as FieldDefinition;
if (field != null && field.Name.StartsWith("CS$<>", StringComparison.Ordinal) && field.IsCompilerGenerated())
return true;
if (field != null) {
if (settings.AnonymousMethods && field.Name.StartsWith("CS$<>", StringComparison.Ordinal) && field.IsCompilerGenerated())
return true;
}
return false;
}
@ -170,7 +178,7 @@ namespace ICSharpCode.Decompiler.Ast
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef))
if (MemberIsHidden(nestedTypeDef, context.Settings))
continue;
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
@ -487,7 +495,7 @@ namespace ICSharpCode.Decompiler.Ast
{
// Add fields
foreach(FieldDefinition fieldDef in typeDef.Fields) {
if (MemberIsHidden(fieldDef)) continue;
if (MemberIsHidden(fieldDef, context.Settings)) continue;
astType.AddChild(CreateField(fieldDef), TypeDeclaration.MemberRole);
}
@ -510,7 +518,7 @@ namespace ICSharpCode.Decompiler.Ast
// Add methods
foreach(MethodDefinition methodDef in typeDef.Methods) {
if (methodDef.IsConstructor || MemberIsHidden(methodDef)) continue;
if (methodDef.IsConstructor || MemberIsHidden(methodDef, context.Settings)) continue;
astType.AddChild(CreateMethod(methodDef), TypeDeclaration.MemberRole);
}

2
ILSpy/CSharpLanguage.cs

@ -420,7 +420,7 @@ namespace ICSharpCode.ILSpy
public override bool ShowMember(MemberReference member)
{
return showAllMembers || !AstBuilder.MemberIsHidden(member);
return showAllMembers || !AstBuilder.MemberIsHidden(member, new DecompilationOptions().DecompilerSettings);
}
}
}

2
ILSpy/DecompilationOptions.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy
public DecompilationOptions()
{
this.DecompilerSettings = DecompilerSettingsPanel.LoadDecompilerSettings(ILSpySettings.Load());
this.DecompilerSettings = DecompilerSettingsPanel.CurrentDecompilerSettings;
}
}
}

10
ILSpy/DecompilerSettingsPanel.xaml.cs

@ -31,6 +31,14 @@ namespace ICSharpCode.ILSpy
this.DataContext = LoadDecompilerSettings(settings);
}
static DecompilerSettings currentDecompilerSettings;
public static DecompilerSettings CurrentDecompilerSettings {
get {
return currentDecompilerSettings ?? (currentDecompilerSettings = LoadDecompilerSettings(ILSpySettings.Load()));
}
}
public static DecompilerSettings LoadDecompilerSettings(ILSpySettings settings)
{
XElement e = settings["DecompilerSettings"];
@ -52,6 +60,8 @@ namespace ICSharpCode.ILSpy
existingElement.ReplaceWith(section);
else
root.Add(section);
currentDecompilerSettings = null; // invalidate cached settings
}
}
}

11
ILSpy/MainWindow.xaml.cs

@ -281,15 +281,20 @@ namespace ICSharpCode.ILSpy
}
void filterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
RefreshTreeViewFilter();
if (e.PropertyName == "Language") {
TreeView_SelectionChanged(null, null);
}
}
public void RefreshTreeViewFilter()
{
// filterSettings is mutable; but the ILSpyTreeNode filtering assumes that filter settings are immutable.
// Thus, the main window will use one mutable instance (for data-binding), and assign a new clone to the ILSpyTreeNodes whenever the main
// mutable instance changes.
if (assemblyListTreeNode != null)
assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone();
if (e.PropertyName == "Language") {
TreeView_SelectionChanged(null, null);
}
}
internal AssemblyList AssemblyList {

4
ILSpy/OptionsDialog.xaml.cs

@ -86,8 +86,10 @@ namespace ICSharpCode.ILSpy
{
OptionsDialog dlg = new OptionsDialog();
dlg.Owner = MainWindow.Instance;
if (dlg.ShowDialog() == true)
if (dlg.ShowDialog() == true) {
MainWindow.Instance.RefreshTreeViewFilter();
MainWindow.Instance.RefreshDecompiledView();
}
}
}
}
Loading…
Cancel
Save