Rewrite to direct constructors
This commit is contained in:
@@ -13,6 +13,8 @@ class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
new mROA.Codegen.CoCodegenMethodRepository();
|
||||
new CoCodegenMethodRepository();
|
||||
var builder = new FullMixBuilder();
|
||||
// builder.UseJsonSerialisation();
|
||||
builder.Modules.Add(new CborSerializationToolkit());
|
||||
|
||||
@@ -13,8 +13,4 @@
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="mROA.Codegen" Version="2.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mROA.Codegen
|
||||
public sealed class RemoteTypeBinder
|
||||
{
|
||||
static RemoteTypeBinder(){
|
||||
RemoteInstanceRepository.RemoteTypes = new Dictionary<Type, Type> {
|
||||
RemoteInstanceRepository.RemoteTypeFactories = new Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, RemoteObjectBase>> {
|
||||
<!I remoteTypePair r sep typesSep><!D typesSep>,
|
||||
<!D>
|
||||
};
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace mROA.Codegen
|
||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
#endif
|
||||
_binderTemplate.Insert("remoteTypePair",
|
||||
$"{{ typeof({classSymbol.ToUnityString()}), typeof({namespaceName}.{className}) }}");
|
||||
$"{{ typeof({classSymbol.ToUnityString()}), (i, r, c) => new {namespaceName}.{className}(i, r, c) }}");
|
||||
}
|
||||
|
||||
if (totalMethods.Count != 0)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public interface ICallIndexProvider : IInjectableModule
|
||||
{
|
||||
int[] GetIndecies(Type type);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace mROA.Abstract
|
||||
{
|
||||
int ResisterObject<T>(object o, IEndPointContext context);
|
||||
void ClearObject(ComplexObjectIdentifier id, IEndPointContext context);
|
||||
T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context);
|
||||
T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class;
|
||||
T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared;
|
||||
object GetSingletonObject(Type type, IEndPointContext context);
|
||||
int GetObjectIndex<T>(object o, IEndPointContext context);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace mROA.Implementation.Backend
|
||||
_storage.Free(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
{
|
||||
var value = _storage.GetValue(id.ContextId);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace mROA.Implementation.Backend
|
||||
repository.ClearObject(id, context);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
{
|
||||
var repository = GetRepositoryByClientId(context.OwnerId);
|
||||
return repository.GetObject<T>(id, context);
|
||||
|
||||
@@ -6,10 +6,11 @@ namespace mROA.Implementation.Bootstrap
|
||||
{
|
||||
public class FullMixBuilder
|
||||
{
|
||||
public List<IInjectableModule> Modules { get; } = new() { };
|
||||
public List<IInjectableModule> Modules { get; } = new();
|
||||
|
||||
public void Build()
|
||||
{
|
||||
|
||||
foreach (var module in Modules)
|
||||
foreach (var injection in Modules)
|
||||
module.Inject(injection);
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace mROA.Implementation
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ namespace mROA.Implementation
|
||||
public class RemoteInstanceRepository : IInstanceRepository
|
||||
{
|
||||
private List<RemoteObjectBase> _producedProxys = new();
|
||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||
|
||||
public static Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, RemoteObjectBase>>
|
||||
RemoteTypeFactories = new();
|
||||
|
||||
private IRepresentationModuleProducer? _representationProducer;
|
||||
|
||||
public int HostId { get; set; }
|
||||
@@ -23,7 +26,7 @@ namespace mROA.Implementation
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
{
|
||||
var index = _producedProxys.Find(i => i.Identifier.Equals(id));
|
||||
if (index is not null)
|
||||
@@ -31,20 +34,20 @@ namespace mROA.Implementation
|
||||
if (_representationProducer == null)
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||
if (!RemoteTypeFactories.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
|
||||
representationModule, context)!;
|
||||
var remote = remoteType(id.ContextId,
|
||||
representationModule, context);
|
||||
|
||||
_producedProxys.Add((remote as RemoteObjectBase)!);
|
||||
_producedProxys.Add(remote!);
|
||||
|
||||
return remote;
|
||||
return (remote as T)!;
|
||||
}
|
||||
|
||||
public T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared
|
||||
{
|
||||
return GetSingletonObject(typeof(T), context) as T;
|
||||
return (GetSingletonObject(typeof(T), context) as T)!;
|
||||
}
|
||||
|
||||
public object GetSingletonObject(Type type, IEndPointContext context)
|
||||
@@ -55,10 +58,10 @@ namespace mROA.Implementation
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
|
||||
var instance = Activator.CreateInstance(RemoteTypes[type], -1, representationModule, context);
|
||||
|
||||
var remoteObjectBase = (RemoteObjectBase)instance;
|
||||
|
||||
var instance = RemoteTypeFactories[type](-1, representationModule, context)!;
|
||||
|
||||
var remoteObjectBase = instance;
|
||||
|
||||
_producedProxys.Add(remoteObjectBase);
|
||||
|
||||
return _producedProxys.Last();
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class RemoteObjectFactory : IRemoteObjectFactory
|
||||
{
|
||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||
private IRepresentationModuleProducer? _representationProducer;
|
||||
|
||||
public T Produce<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
if (_representationProducer == null)
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
|
||||
representationModule)!;
|
||||
return remote;
|
||||
}
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
if (dependency is IRepresentationModuleProducer serialisationModule)
|
||||
_representationProducer = serialisationModule;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace mROA.Implementation
|
||||
object UniversalValue { get; set; }
|
||||
}
|
||||
|
||||
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
|
||||
public class SharedObjectShellShell<T> : ISharedObjectShell where T : class
|
||||
{
|
||||
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace mROA.Implementation
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public SharedObjectShellShell()
|
||||
{
|
||||
_value = default;
|
||||
_value = null;
|
||||
EndPointContext = new EndPointContext();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user