mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
runtimeType
This commit is contained in:
@@ -380,9 +380,11 @@ public static class DataSerializer
|
|||||||
|
|
||||||
var typeDef = warehouse.GetLocalTypeDefByType(valueType);
|
var typeDef = warehouse.GetLocalTypeDefByType(valueType);
|
||||||
|
|
||||||
var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode());
|
//var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode());
|
||||||
|
var intVal = Convert.ToInt32((Enum)value);//, (value as Enum).GetTypeCode());
|
||||||
|
|
||||||
var ct = typeDef.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
|
//var ct = typeDef.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
|
||||||
|
var ct = typeDef.Constants.FirstOrDefault(x => Convert.ToInt32(x.Value) == intVal);
|
||||||
|
|
||||||
if (ct == null)
|
if (ct == null)
|
||||||
return new Tdu(TduIdentifier.Null, null, 0, null, null);
|
return new Tdu(TduIdentifier.Null, null, 0, null, null);
|
||||||
@@ -718,8 +720,8 @@ public static class DataSerializer
|
|||||||
var all = DC.Combine(keysTdu, 0, (uint)keysTdu.Length, valuesTdu, 0, (uint)valuesTdu.Length);
|
var all = DC.Combine(keysTdu, 0, (uint)keysTdu.Length, valuesTdu, 0, (uint)valuesTdu.Length);
|
||||||
|
|
||||||
return new Tdu(TduIdentifier.Typed, all, (uint)all.Length,
|
return new Tdu(TduIdentifier.Typed, all, (uint)all.Length,
|
||||||
new TruComposite(TruIdentifier.TypedMap, false, new Tru[] { kt, vt },
|
new TruComposite(TruIdentifier.TypedMap, false, new Tru[] { kt, vt },
|
||||||
value.GetType()),
|
value.GetType()),
|
||||||
connection);
|
connection);
|
||||||
|
|
||||||
|
|
||||||
@@ -864,7 +866,7 @@ public static class DataSerializer
|
|||||||
var rt = new List<byte>();
|
var rt = new List<byte>();
|
||||||
var record = (IRecord)value;
|
var record = (IRecord)value;
|
||||||
|
|
||||||
var recordTru = Tru.FromType(value.GetType(), warehouse) ;
|
var recordTru = Tru.FromType(value.GetType(), warehouse);
|
||||||
|
|
||||||
TypeDef typeDef = null;
|
TypeDef typeDef = null;
|
||||||
|
|
||||||
@@ -882,6 +884,7 @@ public static class DataSerializer
|
|||||||
throw new Exception("Unsupported.");
|
throw new Exception("Unsupported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var pt in typeDef.Properties)
|
foreach (var pt in typeDef.Properties)
|
||||||
{
|
{
|
||||||
var propValue = pt.PropertyInfo.GetValue(record, null);
|
var propValue = pt.PropertyInfo.GetValue(record, null);
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace Esiur.Data
|
|||||||
|
|
||||||
public abstract void SetNotNull(byte flag);
|
public abstract void SetNotNull(byte flag);
|
||||||
|
|
||||||
public abstract Type RuntimeType { get; protected set; }
|
public abstract Type RuntimeType { get; }
|
||||||
|
|
||||||
//public Type? GetRuntimeType(Warehouse warehouse, string domain)
|
//public Type? GetRuntimeType(Warehouse warehouse, string domain)
|
||||||
//{
|
//{
|
||||||
@@ -373,7 +373,9 @@ namespace Esiur.Data
|
|||||||
|
|
||||||
if (remoteAttr != null)
|
if (remoteAttr != null)
|
||||||
{
|
{
|
||||||
var typeDef = warehouse.GetRemoteTypeDefByName(remoteAttr.Domains, remoteAttr.FullName);
|
var typeDef = warehouse.FindProxyTypeDef(remoteAttr.FullName, remoteAttr.Domains);
|
||||||
|
|
||||||
|
return new TruTypeDef(nullable, typeDef);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,14 +11,16 @@ namespace Esiur.Data
|
|||||||
{
|
{
|
||||||
public Tru[] SubTypes;
|
public Tru[] SubTypes;
|
||||||
|
|
||||||
public override Type RuntimeType { get; protected set; }
|
Type _runtimeType;
|
||||||
|
|
||||||
|
public override Type RuntimeType => _runtimeType;
|
||||||
|
|
||||||
public TruComposite(TruIdentifier identifier, bool nullable, Tru[] subTypes, Type? type)
|
public TruComposite(TruIdentifier identifier, bool nullable, Tru[] subTypes, Type? type)
|
||||||
{
|
{
|
||||||
Identifier = identifier;
|
Identifier = identifier;
|
||||||
Nullable = nullable;
|
Nullable = nullable;
|
||||||
SubTypes = subTypes;
|
SubTypes = subTypes;
|
||||||
RuntimeType = type;
|
_runtimeType = type;
|
||||||
//_runtimeType = typeof(Tuple).MakeGenericType(subTypes.Select(x => x.RuntimeType).ToArray());
|
//_runtimeType = typeof(Tuple).MakeGenericType(subTypes.Select(x => x.RuntimeType).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ namespace Esiur.Data
|
|||||||
{
|
{
|
||||||
public class TruPrimitive:Tru
|
public class TruPrimitive:Tru
|
||||||
{
|
{
|
||||||
public override Type RuntimeType { get; protected set; }
|
Type _runtimeType;
|
||||||
|
|
||||||
|
public override Type RuntimeType => _runtimeType;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
@@ -19,7 +21,7 @@ namespace Esiur.Data
|
|||||||
{
|
{
|
||||||
Identifier = identifier;
|
Identifier = identifier;
|
||||||
Nullable = nullable;
|
Nullable = nullable;
|
||||||
RuntimeType = type;
|
_runtimeType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetNull(List<byte> flags)
|
public override void SetNull(List<byte> flags)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Esiur.Protocol;
|
|||||||
using Esiur.Resource;
|
using Esiur.Resource;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Esiur.Data
|
namespace Esiur.Data
|
||||||
@@ -11,7 +12,22 @@ namespace Esiur.Data
|
|||||||
{
|
{
|
||||||
public TypeDef? TypeDef;
|
public TypeDef? TypeDef;
|
||||||
|
|
||||||
public override Type RuntimeType { get; protected set; }
|
Type _runtimeType = null;
|
||||||
|
|
||||||
|
public override Type RuntimeType => _runtimeType ?? UpdateRuntimeType();
|
||||||
|
|
||||||
|
|
||||||
|
private Type UpdateRuntimeType()
|
||||||
|
{
|
||||||
|
if (TypeDef is LocalTypeDef localTypeDef)
|
||||||
|
_runtimeType = localTypeDef.DefinedType ?? typeof(EpResource);
|
||||||
|
else if (TypeDef is RemoteTypeDef remoteTypeDef)
|
||||||
|
{
|
||||||
|
_runtimeType = remoteTypeDef.ProxyType ?? typeof(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _runtimeType ?? typeof(object);
|
||||||
|
}
|
||||||
|
|
||||||
public override void SetNull(List<byte> flags)
|
public override void SetNull(List<byte> flags)
|
||||||
{
|
{
|
||||||
@@ -28,11 +44,7 @@ namespace Esiur.Data
|
|||||||
Nullable = nullable;
|
Nullable = nullable;
|
||||||
TypeDef = typeDef;
|
TypeDef = typeDef;
|
||||||
|
|
||||||
if (typeDef is LocalTypeDef localTypeDef)
|
UpdateRuntimeType();
|
||||||
RuntimeType = localTypeDef.DefinedType ?? typeof(EpResource);
|
|
||||||
else if (typeDef is RemoteTypeDef remoteTypeDef)
|
|
||||||
RuntimeType = remoteTypeDef.ProxyType ?? typeof(IResource);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetNull(byte flag)
|
public override void SetNull(byte flag)
|
||||||
|
|||||||
@@ -127,6 +127,35 @@ public class RemoteTypeDef:TypeDef
|
|||||||
// try to get proxy type
|
// try to get proxy type
|
||||||
od._proxyType = connection.Instance?.Warehouse?.TryGetProxyType(od.Kind, od.Domain, od.Name);
|
od._proxyType = connection.Instance?.Warehouse?.TryGetProxyType(od.Kind, od.Domain, od.Name);
|
||||||
|
|
||||||
|
if (od._proxyType == null)
|
||||||
|
Console.WriteLine("Proxy type not found " + od.Name);
|
||||||
|
|
||||||
|
if (od._proxyType != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Updating : " + od.Name);
|
||||||
|
|
||||||
|
// update PropertyInfo, MethodInfo, EventInfo, FieldInfo
|
||||||
|
// @TODO Check signature match as well, not only name, to avoid conflicts
|
||||||
|
|
||||||
|
foreach (var prop in od.Properties)
|
||||||
|
prop.PropertyInfo = od._proxyType.GetProperty(prop.Name);
|
||||||
|
|
||||||
|
foreach (var func in od.Functions)
|
||||||
|
func.MethodInfo = od._proxyType.GetMethod(func.Name);
|
||||||
|
|
||||||
|
foreach (var evnt in od.Events)
|
||||||
|
evnt.EventInfo = od._proxyType.GetEvent(evnt.Name);
|
||||||
|
|
||||||
|
foreach(var cons in od.Constants)
|
||||||
|
cons.FieldInfo = od._proxyType.GetField(cons.Name);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// register in warehouse
|
||||||
|
// @TOOD check who is the initiator
|
||||||
|
connection.Instance?.Warehouse?.TryRegisterRemoteTypeDef(connection.RemoteDomain, od);
|
||||||
|
|
||||||
return od;
|
return od;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -848,12 +848,20 @@ public class Warehouse
|
|||||||
return _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
return _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeDef GetProxyTypeDef(string domain, string typeName, TypeDefKind? typeDefKind = null)
|
public TypeDef FindProxyTypeDef(string typeName, string[] domains)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(domain) || !_remoteTypeDefs.ContainsKey(domain))
|
// @TODO: this might cause problems if there are multiple remote type defs with the same name in different domains, we should find a way to handle this case, maybe by adding the domain to the type name or by adding a namespace to the proxy types.
|
||||||
return null;
|
foreach (var domain in domains)
|
||||||
sdcsdc
|
{
|
||||||
return _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
if (!_remoteTypeDefs.ContainsKey(domain))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var typeDef = _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
||||||
|
if (typeDef != null)
|
||||||
|
return typeDef;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public TypeDef GetRemoteTypeDefByType(Type type)
|
//public TypeDef GetRemoteTypeDefByType(Type type)
|
||||||
|
|||||||
Reference in New Issue
Block a user