diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs index 852de74a7..70513583d 100644 --- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs @@ -259,45 +259,43 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler CancellationToken = cancellationToken }, delegate (IGrouping file) { - using (StreamWriter w = new StreamWriter(Path.Combine(TargetDirectory, file.Key))) + try { - try + using StreamWriter w = new StreamWriter(Path.Combine(TargetDirectory, file.Key)); + CSharpDecompiler decompiler = CreateDecompiler(ts); + + foreach (var partialType in partialTypes) { - CSharpDecompiler decompiler = CreateDecompiler(ts); + decompiler.AddPartialTypeDefinition(partialType); + } - foreach (var partialType in partialTypes) + decompiler.CancellationToken = cancellationToken; + var declaredTypes = file.ToArray(); + var syntaxTree = decompiler.DecompileTypes(declaredTypes); + + foreach (var node in syntaxTree.Descendants) + { + var td = (node.GetResolveResult() as TypeResolveResult)?.Type.GetDefinition(); + if (td?.ParentModule != ts.MainModule) + continue; + while (td?.DeclaringTypeDefinition != null) { - decompiler.AddPartialTypeDefinition(partialType); + td = td.DeclaringTypeDefinition; } - - decompiler.CancellationToken = cancellationToken; - var declaredTypes = file.ToArray(); - var syntaxTree = decompiler.DecompileTypes(declaredTypes); - - foreach (var node in syntaxTree.Descendants) + if (td != null && td.MetadataToken is { IsNil: false } token && !processedTypes.Contains((TypeDefinitionHandle)token)) { - var td = (node.GetResolveResult() as TypeResolveResult)?.Type.GetDefinition(); - if (td?.ParentModule != ts.MainModule) - continue; - while (td?.DeclaringTypeDefinition != null) - { - td = td.DeclaringTypeDefinition; - } - if (td != null && td.MetadataToken is { IsNil: false } token && !processedTypes.Contains((TypeDefinitionHandle)token)) + lock (workList) { - lock (workList) - { - workList.Add((TypeDefinitionHandle)token); - } + workList.Add((TypeDefinitionHandle)token); } } - - syntaxTree.AcceptVisitor(new CSharpOutputVisitor(w, Settings.CSharpFormattingOptions)); - } - catch (Exception innerException) when (!(innerException is OperationCanceledException || innerException is DecompilerException)) - { - throw new DecompilerException(module, $"Error decompiling for '{file.Key}'", innerException); } + + syntaxTree.AcceptVisitor(new CSharpOutputVisitor(w, Settings.CSharpFormattingOptions)); + } + catch (Exception innerException) when (!(innerException is OperationCanceledException || innerException is DecompilerException)) + { + throw new DecompilerException(module, $"Error decompiling for '{file.Key}'", innerException); } progress.Status = file.Key; Interlocked.Increment(ref progress.UnitsCompleted);