Browse Source

Fix handling of anonymous types in foreach transform.

pull/870/merge
Siegfried Pammer 8 years ago
parent
commit
83a07239ef
  1. 5
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

5
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -293,7 +293,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -293,7 +293,6 @@ namespace ICSharpCode.Decompiler.CSharp
if (collectionExpr is BaseReferenceExpression) {
collectionExpr = new ThisReferenceExpression().CopyAnnotationsFrom(collectionExpr);
}
if (needsUninlining) {
var type = singleGetter.Method.ReturnType;
ILInstruction instToReplace = singleGetter;
switch (instToReplace.Parent) {
@ -306,6 +305,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -306,6 +305,7 @@ namespace ICSharpCode.Decompiler.CSharp
instToReplace = ua;
break;
}
if (needsUninlining) {
itemVariable = currentFunction.RegisterVariable(
VariableKind.ForeachLocal, type,
AssignVariableNames.GenerateVariableName(currentFunction, collectionExpr.Annotation<ILInstruction>(), "item")
@ -315,6 +315,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -315,6 +315,7 @@ namespace ICSharpCode.Decompiler.CSharp
} else {
if (itemVariable.StoreCount != 1)
return null;
itemVariable.Type = type;
itemVariable.Kind = VariableKind.ForeachLocal;
itemVariable.Name = AssignVariableNames.GenerateVariableName(currentFunction, collectionExpr.Annotation<ILInstruction>(), "item", itemVariable);
}
@ -322,7 +323,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -322,7 +323,7 @@ namespace ICSharpCode.Decompiler.CSharp
BlockStatement foreachBody = (BlockStatement)whileLoop.EmbeddedStatement.Detach();
foreachBody.Statements.First().Detach();
return new ForeachStatement {
VariableType = exprBuilder.ConvertType(itemVariable.Type),
VariableType = settings.AnonymousTypes && itemVariable.Type.ContainsAnonymousType() ? new SimpleType("var") : exprBuilder.ConvertType(itemVariable.Type),
VariableName = itemVariable.Name,
InExpression = collectionExpr.Detach(),
EmbeddedStatement = foreachBody

Loading…
Cancel
Save