кодген переписан по новому принципу
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Frozen;
|
using System.Collections.Frozen;
|
||||||
|
using mROA.Abstract;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
@@ -12,5 +13,4 @@ public interface IPrinterFactory
|
|||||||
SharedObject<IPrinter> GetPrinterByName(string printerName);
|
SharedObject<IPrinter> GetPrinterByName(string printerName);
|
||||||
string[] CollectAllNames();
|
string[] CollectAllNames();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,61 +118,56 @@ namespace {Namespace}
|
|||||||
methods.Add((namespaceName + "." + originalName, method));
|
methods.Add((namespaceName + "." + originalName, method));
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
//Creating signature
|
|
||||||
// if (method.Parameters.Length == 0)
|
|
||||||
// sb.AppendLine($"public {method.ReturnType.ToDisplayString()} {method.Name}(){{");
|
|
||||||
// else
|
|
||||||
|
|
||||||
bool isAsync = method.ReturnType.Name == "Task";
|
bool isAsync = method.ReturnType.Name == "Task";
|
||||||
|
bool isVoid = method.ReturnType.Name == "Void" || method.ReturnType.ToString() == "Task";
|
||||||
|
bool isParametrized = method.Parameters.Length == 1 && !isAsync ||
|
||||||
|
method.Parameters.Length == 2 && isAsync;
|
||||||
|
|
||||||
|
|
||||||
|
//Creating signature
|
||||||
sb.AppendLine("public" + (isAsync
|
sb.AppendLine("public" + (isAsync
|
||||||
? " async "
|
? " async "
|
||||||
: " ") +
|
: " ") +
|
||||||
$"{method.ReturnType.ToDisplayString()} {method.Name}({string.Join(", ", method.Parameters.Select(p => p.ToDisplayString()))}){{");
|
$"{method.ReturnType.ToDisplayString()} {method.Name}({string.Join(", ", method.Parameters.Select(ToFullString))}){{");
|
||||||
|
|
||||||
//Creating request
|
|
||||||
if (method.Parameters.Length == 1 && !isAsync ||
|
|
||||||
method.Parameters.Length == 2 && isAsync)
|
|
||||||
{
|
|
||||||
sb.AppendLine(
|
|
||||||
$"\t\tvar defaultCallRequestCodegen = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id, Parameter = {method.Parameters.First().Name} }};");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.AppendLine(
|
|
||||||
$"\t\tvar defaultCallRequestCodegen = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id }};");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Post created request
|
|
||||||
sb.AppendLine("\t\tserialisationModule.PostCallRequest(defaultCallRequestCodegen);");
|
|
||||||
|
|
||||||
|
|
||||||
if (method.ReturnType.ToString() == "System.Threading.Tasks.Task")
|
var prefix = isAsync ? "await " : "";
|
||||||
{
|
var postfix = !isAsync ? (isVoid? ".Wait()" : ".GetAwaiter().GetResult()") : "";
|
||||||
sb.AppendLine(
|
var parameterLink = isParametrized ? ", " + method.Parameters.First().Name : string.Empty;
|
||||||
"\t\tawait serialisationModule.GetNextCommandExecution<FinalCommandExecution>(defaultCallRequestCodegen.CallRequestId);");
|
var caller = isVoid ? $"CallAsync({index}{parameterLink})" :
|
||||||
}
|
isAsync ? $"GetResultAsync<{ExtractTaskType(method.ReturnType)}>({index}{parameterLink})" :
|
||||||
else if (method.ReturnType.OriginalDefinition.ToString() == "System.Threading.Tasks.Task<TResult>")
|
$"GetResultAsync<{ToFullString(method.ReturnType)}>({index}{parameterLink})";
|
||||||
{
|
|
||||||
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}>(defaultCallRequestCodegen.CallRequestId);");
|
|
||||||
sb.AppendLine($"\t\treturn ({type})response.Result;");
|
|
||||||
}
|
|
||||||
else if (!isAsync && method.ReturnType.ToDisplayString() != "void")
|
|
||||||
{
|
|
||||||
var type = method.ReturnType.ToDisplayString();
|
|
||||||
sb.AppendLine(
|
|
||||||
$"\t\tvar response = serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId).GetAwaiter().GetResult();");
|
|
||||||
sb.AppendLine($"\t\treturn ({type})response.Result;");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.AppendLine(
|
|
||||||
"\t\tserialisationModule.GetNextCommandExecution<FinalCommandExecution>(defaultCallRequestCodegen.CallRequestId).Wait();");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!isVoid)
|
||||||
|
prefix = "return " + prefix;
|
||||||
|
|
||||||
|
// if (method.ReturnType.OriginalDefinition.ToString() == "System.Threading.Tasks.Task<TResult>")
|
||||||
|
// {
|
||||||
|
// 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}>(defaultCallRequestCodegen.CallRequestId);");
|
||||||
|
// sb.AppendLine($"\t\treturn ({type})response.Result;");
|
||||||
|
// }
|
||||||
|
// else if (!isAsync && method.ReturnType.ToDisplayString() != "void")
|
||||||
|
// {
|
||||||
|
// var type = method.ReturnType.ToDisplayString();
|
||||||
|
// sb.AppendLine(
|
||||||
|
// $"\t\tvar response = serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId).GetAwaiter().GetResult();");
|
||||||
|
// sb.AppendLine($"\t\treturn ({type})response.Result;");
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// sb.AppendLine(
|
||||||
|
// "\t\tserialisationModule.GetNextCommandExecution<FinalCommandExecution>(defaultCallRequestCodegen.CallRequestId).Wait();");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// sb.AppendLine("\t}");
|
||||||
|
|
||||||
|
sb.AppendLine("\t\t" + prefix + caller + postfix+ ";");
|
||||||
|
|
||||||
sb.AppendLine("\t}");
|
sb.AppendLine("\t}");
|
||||||
|
|
||||||
methodsText.Add(sb.ToString());
|
methodsText.Add(sb.ToString());
|
||||||
@@ -188,10 +183,11 @@ using mROA.Abstract;
|
|||||||
|
|
||||||
namespace {namespaceName};
|
namespace {namespaceName};
|
||||||
|
|
||||||
partial class {className} (int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : {originalName}, IRemoteObject
|
partial class {className} : RemoteObjectBase, {originalName}
|
||||||
{{
|
{{
|
||||||
public int Id => id;
|
public {className}(int id, IRepresentationModule representationModule) : base(id, representationModule)
|
||||||
public int OwnerId => serialisationModule.ClientId;
|
{{
|
||||||
|
}}
|
||||||
|
|
||||||
{string.Join("\r\n\t", methodsText)}
|
{string.Join("\r\n\t", methodsText)}
|
||||||
}}
|
}}
|
||||||
@@ -270,4 +266,21 @@ public sealed class RemoteTypeBinder
|
|||||||
context.AddSource("RemoteTypeBinder.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
|
context.AddSource("RemoteTypeBinder.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ToFullString(IParameterSymbol parameter)
|
||||||
|
=> /*parameter.Type.ContainingNamespace is null*/
|
||||||
|
/*?*/ parameter.ToDisplayString();
|
||||||
|
/*: $"{parameter.Type.ContainingNamespace.ToDisplayString()}.{parameter.Type.MetadataName} {parameter.Name}";*/
|
||||||
|
|
||||||
|
private static string ToFullString(ITypeSymbol type) =>
|
||||||
|
// => type.ContainingNamespace is null || type.Name == "Void"
|
||||||
|
type.ToDisplayString();
|
||||||
|
// : $"{type.ContainingNamespace.ToDisplayString()}.{type.MetadataName}";
|
||||||
|
|
||||||
|
private string ExtractTaskType(ITypeSymbol taskType)
|
||||||
|
{
|
||||||
|
var type = taskType.ToString();
|
||||||
|
type = type.Substring(type.IndexOf('<') + 1);
|
||||||
|
return type.Substring(0, type.Length - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user