From 32584c07c8b964a68bd4561853cc76a84fda1a17 Mon Sep 17 00:00:00 2001 From: Jb Evain Date: Fri, 20 Jan 2012 11:45:31 +0100 Subject: [PATCH] Fix hiding of mcs generated members --- ICSharpCode.Decompiler/Ast/AstBuilder.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index c1f04e348..206e813c5 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -70,14 +70,14 @@ namespace ICSharpCode.Decompiler.Ast if (method != null) { if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn) return true; - if (settings.AnonymousMethods && method.Name.StartsWith("<", StringComparison.Ordinal) && method.IsCompilerGenerated()) + if (settings.AnonymousMethods && IsGeneratedMemberName(method.Name) && method.IsCompilerGenerated()) return true; } TypeDefinition type = member as TypeDefinition; if (type != null) { - if (type.DeclaringType != null) { - if (settings.AnonymousMethods && type.Name.StartsWith("<>c__DisplayClass", StringComparison.Ordinal) && type.IsCompilerGenerated()) + if (type.DeclaringType != null) { + if (settings.AnonymousMethods && IsGeneratedMemberName(type.Name) && type.IsCompilerGenerated()) return true; if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type)) return true; @@ -91,10 +91,10 @@ namespace ICSharpCode.Decompiler.Ast FieldDefinition field = member as FieldDefinition; if (field != null) { - if (field.IsCompilerGenerated()) { - if (settings.AnonymousMethods && field.Name.StartsWith("CS$<>", StringComparison.Ordinal)) - return true; - if (settings.AutomaticProperties && field.Name.StartsWith("<", StringComparison.Ordinal) && field.Name.EndsWith("BackingField", StringComparison.Ordinal)) + if (field.IsCompilerGenerated()) { + if (settings.AnonymousMethods && (IsGeneratedMemberName(field.Name) || field.Name.StartsWith("CS$<>", StringComparison.Ordinal))) + return true; + if (settings.AutomaticProperties && IsGeneratedMemberName(field.Name) && field.Name.EndsWith("BackingField", StringComparison.Ordinal)) return true; } // event-fields are not [CompilerGenerated] @@ -104,6 +104,11 @@ namespace ICSharpCode.Decompiler.Ast return false; } + + static bool IsGeneratedMemberName(string name) + { + return name.StartsWith("<", StringComparison.Ordinal); + } /// /// Runs the C# transformations on the compilation unit.