Browse Source

Refactor detection of generated member name

pull/307/head
Jb Evain 14 years ago
parent
commit
3d804a162b
  1. 13
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  3. 7
      ICSharpCode.Decompiler/CecilExtensions.cs

13
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -70,14 +70,14 @@ namespace ICSharpCode.Decompiler.Ast
if (method != null) { if (method != null) {
if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn) if (method.IsGetter || method.IsSetter || method.IsAddOn || method.IsRemoveOn)
return true; return true;
if (settings.AnonymousMethods && IsGeneratedMemberName(method.Name) && method.IsCompilerGenerated()) if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated())
return true; return true;
} }
TypeDefinition type = member as TypeDefinition; TypeDefinition type = member as TypeDefinition;
if (type != null) { if (type != null) {
if (type.DeclaringType != null) { if (type.DeclaringType != null) {
if (settings.AnonymousMethods && IsGeneratedMemberName(type.Name) && type.IsCompilerGenerated()) if (settings.AnonymousMethods && type.HasGeneratedName() && type.IsCompilerGenerated())
return true; return true;
if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type)) if (settings.YieldReturn && YieldReturnDecompiler.IsCompilerGeneratorEnumerator(type))
return true; return true;
@ -92,9 +92,9 @@ namespace ICSharpCode.Decompiler.Ast
FieldDefinition field = member as FieldDefinition; FieldDefinition field = member as FieldDefinition;
if (field != null) { if (field != null) {
if (field.IsCompilerGenerated()) { if (field.IsCompilerGenerated()) {
if (settings.AnonymousMethods && (IsGeneratedMemberName(field.Name) || field.Name.StartsWith("CS$<>", StringComparison.Ordinal))) if (settings.AnonymousMethods && (field.HasGeneratedName() || field.Name.StartsWith("CS$<>", StringComparison.Ordinal)))
return true; return true;
if (settings.AutomaticProperties && IsGeneratedMemberName(field.Name) && field.Name.EndsWith("BackingField", StringComparison.Ordinal)) if (settings.AutomaticProperties && field.HasGeneratedName() && field.Name.EndsWith("BackingField", StringComparison.Ordinal))
return true; return true;
} }
// event-fields are not [CompilerGenerated] // event-fields are not [CompilerGenerated]
@ -105,11 +105,6 @@ namespace ICSharpCode.Decompiler.Ast
return false; return false;
} }
static bool IsGeneratedMemberName(string name)
{
return name.StartsWith("<", StringComparison.Ordinal);
}
/// <summary> /// <summary>
/// Runs the C# transformations on the compilation unit. /// Runs the C# transformations on the compilation unit.
/// </summary> /// </summary>

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

@ -115,7 +115,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
internal static bool IsAnonymousMethod(DecompilerContext context, MethodDefinition method) 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; return false;
if (!(method.IsCompilerGenerated() || IsPotentialClosure(context, method.DeclaringType))) if (!(method.IsCompilerGenerated() || IsPotentialClosure(context, method.DeclaringType)))
return false; return false;

7
ICSharpCode.Decompiler/CecilExtensions.cs

@ -220,13 +220,18 @@ namespace ICSharpCode.Decompiler
{ {
if (type == null) if (type == null)
return false; 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("Anon")) {
TypeDefinition td = type.Resolve(); TypeDefinition td = type.Resolve();
return td != null && td.IsCompilerGenerated(); return td != null && td.IsCompilerGenerated();
} }
return false; return false;
} }
public static bool HasGeneratedName(this MemberReference member)
{
return member.Name.StartsWith("<", StringComparison.Ordinal);
}
public static bool ContainsAnonymousType(this TypeReference type) public static bool ContainsAnonymousType(this TypeReference type)
{ {
GenericInstanceType git = type as GenericInstanceType; GenericInstanceType git = type as GenericInstanceType;

Loading…
Cancel
Save