кодген фронтенд репозитория реализован
This commit is contained in:
@@ -84,7 +84,7 @@ namespace {Namespace}
|
||||
ImmutableArray<InterfaceDeclarationSyntax> classDeclarations)
|
||||
{
|
||||
var methods = new List<(string, IMethodSymbol)>();
|
||||
|
||||
var frontendContextRepo = new List<string>();
|
||||
// Go through all filtered class declarations.
|
||||
foreach (var classDeclarationSyntax in classDeclarations)
|
||||
{
|
||||
@@ -96,6 +96,7 @@ namespace {Namespace}
|
||||
if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
|
||||
continue;
|
||||
|
||||
|
||||
var namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
|
||||
// 'Identifier' means the token of the node. Get class name from the syntax node.
|
||||
@@ -191,6 +192,8 @@ partial class {className} (int id, ISerialisationModule.IFrontendSerialisationMo
|
||||
|
||||
// Add the source code to the compilation.
|
||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
|
||||
frontendContextRepo.Add($"{{ typeof({classSymbol.ToDisplayString()}), typeof({namespaceName}.{className}) }}");
|
||||
}
|
||||
|
||||
|
||||
@@ -230,5 +233,57 @@ public class CoCodegenMethodRepository :IMethodRepository
|
||||
}}
|
||||
";
|
||||
context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
|
||||
|
||||
var fronendRepoCode = @$"// <auto-generated/>
|
||||
using System.Collections.Frozen;
|
||||
|
||||
namespace mROA.Implementation;
|
||||
|
||||
public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository
|
||||
{{
|
||||
private static readonly FrozenDictionary<Type, Type> _remoteTypes = new Dictionary<Type, Type> {{
|
||||
{string.Join(", \r\n\t\t", frontendContextRepo)}}}.ToFrozenDictionary();
|
||||
|
||||
public int ResisterObject(object o)
|
||||
{{
|
||||
throw new NotSupportedException();
|
||||
}}
|
||||
|
||||
public void ClearObject(int id)
|
||||
{{
|
||||
throw new NotSupportedException();
|
||||
}}
|
||||
|
||||
public object GetObject(int id)
|
||||
{{
|
||||
throw new NotSupportedException();
|
||||
}}
|
||||
|
||||
public T GetObject<T>(int id)
|
||||
{{
|
||||
if (_remoteTypes.TryGetValue(typeof(T), out var remoteType))
|
||||
{{
|
||||
var remote = (T)Activator.CreateInstance(remoteType, id, serialisationModule)!;
|
||||
return remote;
|
||||
}}
|
||||
throw new NotSupportedException();
|
||||
}}
|
||||
|
||||
public object GetSingleObject(Type type)
|
||||
{{
|
||||
return Activator.CreateInstance(_remoteTypes[type], -1, serialisationModule)!;
|
||||
}}
|
||||
|
||||
public int GetObjectIndex(object o)
|
||||
{{
|
||||
if (o is IRemoteObject remote)
|
||||
{{
|
||||
return remote.Id;
|
||||
}}
|
||||
throw new NotSupportedException();
|
||||
}}
|
||||
}}
|
||||
";
|
||||
context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user