Решена ошибка кодгена при генерации асинхронных методов в генерик возвращаемым типом

This commit is contained in:
2025-02-05 23:46:06 +03:00
parent d780d0ea0b
commit 5bcdb968f0
13 changed files with 115 additions and 118 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ public class Printer : IPrinter
return Name;
}
public TransmittedSharedObject<IPage> Print(string text)
public async Task<TransmittedSharedObject<IPage>> Print(string text)
{
return new Page {Text = text};
}
+1 -1
View File
@@ -6,6 +6,6 @@ namespace Example.Shared;
public interface IPrinter
{
string GetName();
TransmittedSharedObject<IPage> Print(string text);
Task<TransmittedSharedObject<IPage>> Print(string text);
}
+1 -1
View File
@@ -3,7 +3,7 @@
"profiles": {
"DebugRoslynSourceGenerator": {
"commandName": "DebugRoslynComponent",
"targetProject": "../Example.Backend/Example.Backend.csproj"
"targetProject": "../Example.Shared/Example.Shared.csproj"
}
}
}
@@ -154,8 +154,10 @@ namespace {Namespace}
}
else if (method.ReturnType.OriginalDefinition.ToString() == "System.Threading.Tasks.Task<TResult>")
{
var type = method.ReturnType.ToString().Split(['<', '>'], StringSplitOptions.RemoveEmptyEntries)
.Last();
var type = method.ReturnType.ToString();
type = type.Substring(type.IndexOf('<') + 1);
type = type.Substring(0, type.Length - 1);
sb.AppendLine(
$"\t\tvar response = await serialisationModule.GetFinalCommandExecution<{type}>(request.CallRequestId);");
sb.AppendLine($"\t\treturn ({type})response.Result;");
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+47c67a22afbe9bd7560c8687b1d56893fcdd2fad")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -5,18 +5,18 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
</PropertyGroup>
</Project>
+92 -96
View File
@@ -1,96 +1,92 @@
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using mROA.Abstract;
using mROA.Codegen;
using Example.Shared;
using mROA.Implementation;
namespace mROA.Test;
public class FrontendFinalTest
{
private StreamBasedInteractionModule _interactionModule;
private StreamBasedFrontendInteractionModule _frontendInteractionModule;
private JsonFrontendSerialisationModule _frontendSerialisationModule;
private ISerialisationModule _serialisationModule;
private IExecuteModule _executeModule;
private IMethodRepository _methodRepository;
private IContextRepository _contextRepository;
bool isTestNotFinished = true;
private IContextRepository _frontendContextRepository;
[SetUp]
public void Setup()
{
_methodRepository = new CoCodegenMethodRepository();
var repo2 = new ContextRepository();
repo2.FillSingletons(typeof(ITestController).Assembly);
_contextRepository = repo2;
_interactionModule = new StreamBasedInteractionModule();
_serialisationModule = new JsonSerialisationModule();
_executeModule = new BasicExecutionModule();
IInjectableModule[] backendModules = [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule];
foreach (var backendModule in backendModules)
foreach (var injection in backendModules)
backendModule.Inject(injection);
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
_frontendSerialisationModule = new JsonFrontendSerialisationModule();
_frontendContextRepository = new FrontendContextRepository();
IInjectableModule[] frontendModules = [_frontendInteractionModule, _frontendSerialisationModule, _frontendContextRepository];
foreach (var backendModule in frontendModules)
foreach (var injection in frontendModules)
backendModule.Inject(injection);
Task.Run(() =>
{
TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
listener.Start();
var stream = listener.AcceptTcpClient().GetStream();
Console.WriteLine("Client connected");
_interactionModule.RegisterSourse(stream);
while (isTestNotFinished) ;
});
var tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Loopback, 4567);
_frontendInteractionModule.ServerStream = tcpClient.GetStream();
}
[Test]
public void CallTest()
{
var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
var x = singleton.B();
Console.WriteLine(x);
}
[Test]
public void TransmittionTest()
{
var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
var next = singleton.SharedObjectTransmitionTest().Value;
var parameter = singleton.GetTestParameter().Value;
var x = next.Parametrized(new TestParameter { A = 100, LinkedObject = new (parameter!)});
}
}
// using System.Net;
// using System.Net.Sockets;
// using System.Reflection;
// using mROA.Abstract;
// using mROA.Codegen;
// using Example.Shared;
// using mROA.Implementation;
//
// namespace mROA.Test;
//
// public class FrontendFinalTest
// {
// private StreamBasedInteractionModule _interactionModule;
// private StreamBasedFrontendInteractionModule _frontendInteractionModule;
// private JsonFrontendSerialisationModule _frontendSerialisationModule;
// private ISerialisationModule _serialisationModule;
// private IExecuteModule _executeModule;
// private IMethodRepository _methodRepository;
// private IContextRepository _contextRepository;
// bool isTestNotFinished = true;
// private IContextRepository _frontendContextRepository;
//
// [SetUp]
// public void Setup()
// {
// _methodRepository = new CoCodegenMethodRepository();
// var repo2 = new ContextRepository();
// repo2.FillSingletons(typeof(ITestController).Assembly);
// _contextRepository = repo2;
//
// _interactionModule = new StreamBasedInteractionModule();
//
// _serialisationModule = new JsonSerialisationModule();
//
// _executeModule = new BasicExecutionModule();
//
// IInjectableModule[] backendModules =
// [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule];
//
// foreach (var backendModule in backendModules)
// foreach (var injection in backendModules)
// backendModule.Inject(injection);
//
// _frontendInteractionModule = new StreamBasedFrontendInteractionModule();
// _frontendSerialisationModule = new JsonFrontendSerialisationModule();
// _frontendContextRepository = new FrontendContextRepository();
//
// IInjectableModule[] frontendModules =
// [_frontendInteractionModule, _frontendSerialisationModule, _frontendContextRepository];
//
// foreach (var backendModule in frontendModules)
// foreach (var injection in frontendModules)
// backendModule.Inject(injection);
//
// Task.Run(() =>
// {
// TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
// listener.Start();
//
// var stream = listener.AcceptTcpClient().GetStream();
//
// Console.WriteLine("Client connected");
//
// _interactionModule.RegisterSourse(stream);
//
// while (isTestNotFinished) ;
// });
//
// var tcpClient = new TcpClient();
// tcpClient.Connect(IPAddress.Loopback, 4567);
// _frontendInteractionModule.ServerStream = tcpClient.GetStream();
// }
//
// [Test]
// public void CallTest()
// {
// var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
//
// var x = singleton.B();
// Console.WriteLine(x);
// }
//
// [Test]
// public void TransmittionTest()
// {
// var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
//
// var next = singleton.SharedObjectTransmitionTest().Value;
// var parameter = singleton.GetTestParameter().Value;
// var x = next.Parametrized(new TestParameter { A = 100, LinkedObject = new(parameter!) });
// }
// }
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+47c67a22afbe9bd7560c8687b1d56893fcdd2fad")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+3 -3
View File
@@ -5,12 +5,12 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
@@ -21,6 +21,6 @@
<Import Project="$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
</PropertyGroup>
</Project>
+4 -5
View File
@@ -1,10 +1,9 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
// This code was generated by a tool.
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
@@ -14,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+47c67a22afbe9bd7560c8687b1d56893fcdd2fad")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -8,7 +8,7 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = mROA
build_property.ProjectDir = C:\Users\Mikhail\Projects\VisualStudioProjects\mROA\mROA\
build_property.ProjectDir = C:\Users\Mimm\Projects\VisualStudioProjects\mROA\mROA\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
+2 -2
View File
@@ -5,12 +5,12 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>