Browse Source

TransformCollectionAndObjectInitializers: Do not transform display class usages

pull/734/merge
Siegfried Pammer 8 years ago
parent
commit
c5d3218834
  1. 10
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs
  2. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

10
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -57,7 +57,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var newObj = value as NewObj;
// TODO : it is probably not a good idea to remove *all* display-classes
// is there a way to minimize the false-positives?
if (newObj != null && IsSimpleDisplayClass(newObj.Method)) {
if (newObj != null && IsInSimpleDisplayClass(newObj.Method)) {
targetVariable.CaptureScope = FindBlockContainer(block);
targetsToReplace.Add((IInstructionWithVariableOperand)block.Instructions[i]);
}
@ -78,11 +78,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -78,11 +78,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return BlockContainer.FindClosestContainer(block) ?? throw new NotSupportedException();
}
bool IsSimpleDisplayClass(IMethod method)
static bool IsInSimpleDisplayClass(IMethod method)
{
if (!method.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return false;
var type = method.DeclaringType;
return IsSimpleDisplayClass(method.DeclaringType);
}
internal static bool IsSimpleDisplayClass(IType type)
{
if (!type.HasGeneratedName() || (!type.Name.Contains("DisplayClass") && !type.Name.Contains("AnonStorey")))
return false;
if (type.DirectBaseTypes.Any(t => !t.IsKnownType(KnownTypeCode.Object)))

4
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -47,6 +47,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -47,6 +47,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Block initializerBlock = null;
switch (initInst) {
case NewObj newObjInst:
// Do not try to transform display class usages or delegate construction.
// DelegateConstruction transform cannot deal with this.
if (DelegateConstruction.IsSimpleDisplayClass(newObjInst.Method.DeclaringType))
return false;
if (DelegateConstruction.IsDelegateConstruction(newObjInst) || DelegateConstruction.IsPotentialClosure(context, newObjInst))
return false;
break;

Loading…
Cancel
Save