Юнити кодген работает

This commit is contained in:
2025-03-30 12:43:58 +03:00
parent e31510b27b
commit b675553b6e
3 changed files with 26 additions and 4 deletions
+12
View File
@@ -0,0 +1,12 @@
// <auto-generated/>
namespace RPCTest.Implementation
{
public sealed class GenerativeParametersTestClass
{
public int Increment(<!L param>)
{
return i + 1;
}
}
}
+1
View File
@@ -37,6 +37,7 @@
<EmbeddedResource Include="PartialInterface.cstmpl"/>
<EmbeddedResource Include="RemoteEndpoint.cstmpl"/>
<EmbeddedResource Include="RemoteTypeBinder.cstmpl"/>
<EmbeddedResource Include="TestClass.cstmpl" />
<None Remove="MethodRepo.cstmpl"/>
<EmbeddedResource Include="MethodRepo.cstmpl"/>
</ItemGroup>
+13 -4
View File
@@ -22,7 +22,7 @@ namespace mROA.Codegen
/// performance overhead.
/// </summary>
[Generator]
public class MRoaSourceGenerator : ISourceGenerator
public class mROAGenerator : ISourceGenerator
{
private static readonly Predicate<IParameterSymbol> ParameterFilter =
i => i.Type.Name is "CancellationToken" or "RequestContext";
@@ -136,7 +136,7 @@ namespace mROA.Codegen
string impl;
if (propertySymbol.IsIndexer)
impl =
$"public {propertySymbol.Type.ToUnityString()} this[{string.Join(", ", propertySymbol.Parameters.Select(p => p.ToDisplayString()))}] {{ {getter.Item1} {setter.Item1} }}";
$"public {propertySymbol.Type.ToUnityString()} this[{string.Join(", ", propertySymbol.Parameters.Select(p => p.ToUnityString()))}] {{ {getter.Item1} {setter.Item1} }}";
else
impl =
$"public {propertySymbol.Type.ToUnityString()} {symbol.Name} {{ {getter.Item1} {setter.Item1} }}";
@@ -173,6 +173,10 @@ namespace mROA.Codegen
{
var coCodegenRepoCode = _methodRepoTemplate.Compile();
#if !DONT_ADD
var template = TemplateReader.FromEmbeddedResource("TestClass.cstmpl");
template.AddDefine("param", "System.Int32 i");
context.AddSource("TestClass.g.cs", SourceText.From(template.Compile(), Encoding.UTF8));
context.AddSource("CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
#endif
}
@@ -558,9 +562,9 @@ namespace mROA.Codegen
private static string ToFullString(IParameterSymbol parameter)
{
return parameter.ToDisplayParts().ToUnityString();
return parameter.Type.ToUnityString() + " " + parameter.Name;
}
private static string ToFullString(ITypeSymbol type)
{
return type.ToUnityString();
@@ -613,6 +617,11 @@ namespace mROA.Codegen
return type.ToDisplayString();
}
public static string ToUnityString(this IParameterSymbol parameter)
{
return parameter.Type.ToUnityString() + " " + parameter.Name;
}
public static string ToUnityString(this ImmutableArray<SymbolDisplayPart> parts)
{
var sb = new StringBuilder();