|
|
@ -180,8 +180,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms |
|
|
|
foreach (AstNode node in body.Descendants) { |
|
|
|
foreach (AstNode node in body.Descendants) { |
|
|
|
if (node is ThisReferenceExpression) |
|
|
|
if (node is ThisReferenceExpression) |
|
|
|
node.ReplaceWith(target.Clone()); |
|
|
|
node.ReplaceWith(target.Clone()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Expression replacement; |
|
|
|
if (isLambda) { |
|
|
|
if (isLambda) { |
|
|
|
LambdaExpression lambda = new LambdaExpression(); |
|
|
|
LambdaExpression lambda = new LambdaExpression(); |
|
|
|
lambda.CopyAnnotationsFrom(ame); |
|
|
|
lambda.CopyAnnotationsFrom(ame); |
|
|
@ -189,13 +189,32 @@ namespace ICSharpCode.Decompiler.Ast.Transforms |
|
|
|
Expression returnExpr = ((ReturnStatement)body.Statements.Single()).Expression; |
|
|
|
Expression returnExpr = ((ReturnStatement)body.Statements.Single()).Expression; |
|
|
|
returnExpr.Remove(); |
|
|
|
returnExpr.Remove(); |
|
|
|
lambda.Body = returnExpr; |
|
|
|
lambda.Body = returnExpr; |
|
|
|
objectCreateExpression.ReplaceWith(lambda); |
|
|
|
replacement = lambda; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ame.Body = body; |
|
|
|
ame.Body = body; |
|
|
|
objectCreateExpression.ReplaceWith(ame); |
|
|
|
replacement = ame; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var expectedType = objectCreateExpression.Annotation<TypeInformation>().ExpectedType.Resolve(); |
|
|
|
|
|
|
|
if (expectedType != null && !IsDelegate(expectedType)) { |
|
|
|
|
|
|
|
var simplifiedDelegateCreation = (ObjectCreateExpression)objectCreateExpression.Clone(); |
|
|
|
|
|
|
|
simplifiedDelegateCreation.Arguments.Clear(); |
|
|
|
|
|
|
|
simplifiedDelegateCreation.Arguments.Add(replacement); |
|
|
|
|
|
|
|
replacement = simplifiedDelegateCreation; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
objectCreateExpression.ReplaceWith(replacement); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool IsDelegate(TypeDefinition type) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (type.BaseType != null && type.BaseType.Namespace == "System") { |
|
|
|
|
|
|
|
if (type.BaseType.Name == "MulticastDelegate") |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
if (type.BaseType.Name == "Delegate" && type.Name != "MulticastDelegate") |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass) |
|
|
|
internal static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass) |
|
|
|
{ |
|
|
|
{ |
|
|
|