Browse Source

Merge pull request #307 from jbevain-forks/mcsGeneratedMemberRemoval

Fix hiding of mcs generated members
pull/309/merge
Daniel Grunwald 14 years ago
parent
commit
703274feac
  1. 36
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  3. 7
      ICSharpCode.Decompiler/CecilExtensions.cs

36
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -70,14 +70,14 @@ namespace ICSharpCode.Decompiler.Ast @@ -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 && method.HasGeneratedName() && 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 && IsClosureType(type))
return true;
if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type))
return true;
@ -91,10 +91,12 @@ namespace ICSharpCode.Decompiler.Ast @@ -91,10 +91,12 @@ 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 && IsAnonymousMethodCacheField(field))
return true;
if (settings.AutomaticProperties && IsAutomaticPropertyBackingField(field))
return true;
if (settings.SwitchStatementOnString && IsSwitchOnStringCache(field))
return true;
}
// event-fields are not [CompilerGenerated]
@ -104,6 +106,26 @@ namespace ICSharpCode.Decompiler.Ast @@ -104,6 +106,26 @@ namespace ICSharpCode.Decompiler.Ast
return false;
}
static bool IsSwitchOnStringCache(FieldDefinition field)
{
return field.Name.StartsWith("<>f__switch", StringComparison.Ordinal);
}
static bool IsAutomaticPropertyBackingField(FieldDefinition field)
{
return field.HasGeneratedName() && field.Name.EndsWith("BackingField", StringComparison.Ordinal);
}
static bool IsAnonymousMethodCacheField(FieldDefinition field)
{
return field.Name.StartsWith("CS$<>", StringComparison.Ordinal) || field.Name.StartsWith("<>f__am", StringComparison.Ordinal);
}
static bool IsClosureType(TypeDefinition type)
{
return type.HasGeneratedName() && type.IsCompilerGenerated() && (type.Name.Contains("DisplayClass") || type.Name.Contains("AnonStorey"));
}
/// <summary>
/// Runs the C# transformations on the compilation unit.

2
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
internal static bool IsAnonymousMethod(DecompilerContext context, MethodDefinition method)
{
if (method == null || !(method.Name.StartsWith("<", StringComparison.Ordinal) || method.Name.Contains("$")))
if (method == null || !(method.HasGeneratedName() || method.Name.Contains("$")))
return false;
if (!(method.IsCompilerGenerated() || IsPotentialClosure(context, method.DeclaringType)))
return false;

7
ICSharpCode.Decompiler/CecilExtensions.cs

@ -237,12 +237,17 @@ namespace ICSharpCode.Decompiler @@ -237,12 +237,17 @@ namespace ICSharpCode.Decompiler
{
if (type == null)
return false;
if (string.IsNullOrEmpty(type.Namespace) && type.Name.StartsWith("<>", StringComparison.Ordinal) && type.Name.Contains("AnonymousType")) {
if (string.IsNullOrEmpty(type.Namespace) && type.HasGeneratedName() && (type.Name.Contains("AnonType") || type.Name.Contains("AnonymousType"))) {
TypeDefinition td = type.Resolve();
return td != null && td.IsCompilerGenerated();
}
return false;
}
public static bool HasGeneratedName(this MemberReference member)
{
return member.Name.StartsWith("<", StringComparison.Ordinal);
}
public static bool ContainsAnonymousType(this TypeReference type)
{

Loading…
Cancel
Save