Skip to content

Commit 7be9aa5

Browse files
committed
Bump dependencies, update ILSharpCode.Decompiler
1 parent 9cc1b6a commit 7be9aa5

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

CSharpRepl.Tests/CSharpRepl.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1212
</ItemGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.0-rc.2.22476.2" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221003-04" />
14+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.4" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
1616
<PackageReference Include="xunit" Version="2.4.2" />
1717
<PackageReference Include="xunit.runner.reporters" Version="2.4.2" />
1818
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">

CSharpRepl/CSharpRepl.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="AngouriMath" Version="1.3.0" />
17-
<PackageReference Include="ICSharpCode.Decompiler" Version="3.2.0.3856" />
18-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0-1.22524.5" />
19-
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
20-
<PackageReference Include="NuGet.Packaging" Version="6.5.0-preview.1.35" />
21-
<PackageReference Include="NuGet.Protocol" Version="6.5.0-preview.1.35" />
22-
<PackageReference Include="NuGet.Resolver" Version="6.5.0-preview.1.35" />
17+
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7313-preview4" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
19+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
20+
<PackageReference Include="NuGet.Resolver" Version="6.5.0" />
2321
<PackageReference Include="Seq.Extensions.Logging" Version="6.1.0" />
2422
</ItemGroup>
2523
<ItemGroup>

CSharpRepl/Eval/DisassemblyService.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using ICSharpCode.Decompiler.Disassembler;
33
using Microsoft.CodeAnalysis;
44
using Microsoft.CodeAnalysis.CSharp;
5-
using Mono.Cecil;
65
using Newtonsoft.Json;
76
using System;
87
using System.Collections.Generic;
@@ -15,6 +14,7 @@
1514
using System.Text;
1615
using System.Text.RegularExpressions;
1716
using System.Threading;
17+
using ICSharpCode.Decompiler.Metadata;
1818

1919
namespace CSDiscordService.Eval
2020
{
@@ -75,17 +75,21 @@ public object Main()
7575
}}
7676
";
7777

78-
var opts = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview).WithKind(SourceCodeKind.Regular);
78+
var opts = CSharpParseOptions.Default
79+
.WithLanguageVersion(LanguageVersion.Preview)
80+
.WithKind(SourceCodeKind.Regular);
7981

8082
var scriptSyntaxTree = CSharpSyntaxTree.ParseText(toExecute, opts);
81-
var compOpts = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithOptimizationLevel(OptimizationLevel.Debug).WithAllowUnsafe(true).WithPlatform(Platform.AnyCpu);
83+
var compOpts = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
84+
.WithOptimizationLevel(OptimizationLevel.Debug)
85+
.WithAllowUnsafe(true).WithPlatform(Platform.AnyCpu);
8286

83-
var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString(), options: compOpts, references: References).AddSyntaxTrees(scriptSyntaxTree);
87+
var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString(), options: compOpts, references: References)
88+
.AddSyntaxTrees(scriptSyntaxTree);
8489

8590
var sb = new StringBuilder();
86-
using var pdb = new MemoryStream();
8791
using var dll = new MemoryStream();
88-
var result = compilation.Emit(dll, pdb);
92+
var result = compilation.Emit(dll);
8993
if (!result.Success)
9094
{
9195
sb.AppendLine("Emit Failed");
@@ -94,19 +98,22 @@ public object Main()
9498
else
9599
{
96100
dll.Seek(0, SeekOrigin.Begin);
97-
using var module = ModuleDefinition.ReadModule(dll);
101+
using var file = new PEFile(compilation.AssemblyName!, dll);
98102
using var writer = new StringWriter(sb);
99-
module.Name = compilation.AssemblyName;
100103
var plainOutput = new PlainTextOutput(writer);
101104
var rd = new ReflectionDisassembler(plainOutput, CancellationToken.None)
102105
{
103106
DetectControlStructure = true
104107
};
105108
var ignoredMethods = new[] { ".ctor" };
106-
var methods = module.Types.SelectMany(a => a.Methods).Where(a => !ignoredMethods.Contains(a.Name));
109+
var methods = file.Metadata.MethodDefinitions.Where(a =>
110+
{
111+
var methodName = file.Metadata.GetString(file.Metadata.GetMethodDefinition(a).Name);
112+
return !ignoredMethods.Contains(methodName);
113+
});
107114
foreach (var method in methods)
108115
{
109-
rd.DisassembleMethod(method);
116+
rd.DisassembleMethod(file, method);
110117
plainOutput.WriteLine();
111118
}
112119
}

0 commit comments

Comments
 (0)