Browse Source

Fix decompilation of yield return in local functions.

pull/1612/head
Siegfried Pammer 6 years ago
parent
commit
c51aea3601
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs
  2. 2
      ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs
  3. 11
      ICSharpCode.Decompiler/SRMExtensions.cs

13
ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs

@ -273,6 +273,19 @@ namespace LocalFunctions @@ -273,6 +273,19 @@ namespace LocalFunctions
}
});
}
public static IEnumerable<int> YieldReturn(int n)
{
return GetNumbers();
IEnumerable<int> GetNumbers()
{
for (int i = 0; i < n; i++) {
yield return i;
}
}
}
//public static void LocalFunctionInUsing()
//{
// using (MemoryStream memoryStream = new MemoryStream()) {

2
ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

@ -338,7 +338,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -338,7 +338,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
public static bool IsCompilerGeneratorEnumerator(TypeDefinitionHandle type, MetadataReader metadata)
{
TypeDefinition td;
if (type.IsNil || !type.IsCompilerGenerated(metadata) || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil)
if (type.IsNil || !type.IsCompilerGeneratedOrIsInCompilerGeneratedClass(metadata) || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil)
return false;
foreach (var i in td.GetInterfaceImplementations()) {
var tr = metadata.GetInterfaceImplementation(i).Interface.GetFullTypeName(metadata);

11
ICSharpCode.Decompiler/SRMExtensions.cs

@ -309,6 +309,17 @@ namespace ICSharpCode.Decompiler @@ -309,6 +309,17 @@ namespace ICSharpCode.Decompiler
return false;
}
public static bool IsCompilerGeneratedOrIsInCompilerGeneratedClass(this TypeDefinitionHandle handle, MetadataReader metadata)
{
TypeDefinition type = metadata.GetTypeDefinition(handle);
if (type.IsCompilerGenerated(metadata))
return true;
TypeDefinitionHandle declaringTypeHandle = type.GetDeclaringType();
if (!declaringTypeHandle.IsNil && declaringTypeHandle.IsCompilerGenerated(metadata))
return true;
return false;
}
public static bool IsCompilerGenerated(this MethodDefinition method, MetadataReader metadata)
{
return method.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.CompilerGenerated);

Loading…
Cancel
Save