diff --git a/Esiur/Data/RepresentationType.cs b/Esiur/Data/RepresentationType.cs index 0c29830..3111ca3 100644 --- a/Esiur/Data/RepresentationType.cs +++ b/Esiur/Data/RepresentationType.cs @@ -1,4 +1,5 @@ -using Esiur.Net.IIP; +using Esiur.Core; +using Esiur.Net.IIP; using Esiur.Resource; using Esiur.Resource.Template; using System; @@ -131,6 +132,24 @@ namespace Esiur.Data public Type? GetRuntimeType() { + + if (Identifier == RepresentationTypeIdentifier.TypedList) + { + var sub = SubTypes[0].GetRuntimeType(); + if (sub == null) + return null; + + var rt = sub.MakeArrayType(); + + return rt; + } + else if (Identifier == RepresentationTypeIdentifier.TypedMap) + { + var subs = SubTypes.Select(x => x.GetRuntimeType()).ToArray(); + var rt = typeof(Map<,>).MakeGenericType(subs); + return rt; + } + return Identifier switch { (RepresentationTypeIdentifier.Void) => typeof(void), @@ -155,6 +174,7 @@ namespace Esiur.Data (RepresentationTypeIdentifier.TypedRecord) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Record).DefinedType, (RepresentationTypeIdentifier.TypedResource) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Unspecified).DefinedType, (RepresentationTypeIdentifier.Enum) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Enum).DefinedType, + _ => null }; } @@ -249,11 +269,16 @@ namespace Esiur.Data return new RepresentationType(RepresentationTypeIdentifier.TypedMap, nullable, null, subType1, subType2); } } - else if (genericType == typeof(DistributedPropertyContext<>)) - { - var args = type.GetGenericArguments(); - return FromType(args[0]); - } + //else if (genericType == typeof(AsyncReply<>)) + //{ + // var args = type.GetGenericArguments(); + // return FromType(args[0]); + //} + //else if (genericType == typeof(DistributedPropertyContext<>)) + //{ + // var args = type.GetGenericArguments(); + // return FromType(args[0]); + //} else if (genericType == typeof(ValueTuple<,>)) { var args = type.GetGenericArguments(); diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 8d4fbad..6f95e7e 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -6,7 +6,7 @@ Ahmed Kh. Zamil http://www.esiur.com true - 2.2.3 + 2.2.4.4 https://github.com/esiur/esiur-dotnet Ahmed Kh. Zamil diff --git a/Esiur/Proxy/TemplateGenerator.cs b/Esiur/Proxy/TemplateGenerator.cs index 9bcf40e..ccd277e 100644 --- a/Esiur/Proxy/TemplateGenerator.cs +++ b/Esiur/Proxy/TemplateGenerator.cs @@ -289,7 +289,7 @@ public static class TemplateGenerator var optionalArgs = f.Arguments.Where((x) => x.Optional).ToArray(); - rt.Append($"public AsyncReply<{rtTypeName}> {f.Name}("); + rt.Append($"[Public] public AsyncReply<{rtTypeName}> {f.Name}("); if (positionalArgs.Length > 0) @@ -332,7 +332,7 @@ public static class TemplateGenerator continue; var ptTypeName = GetTypeName(p.ValueType, templates); - rt.AppendLine($"public {ptTypeName} {p.Name} {{"); + rt.AppendLine($"[Public] public {ptTypeName} {p.Name} {{"); rt.AppendLine($"get => ({ptTypeName})properties[{p.Index}];"); rt.AppendLine($"set => _Set({p.Index}, value);"); rt.AppendLine("}"); @@ -344,7 +344,7 @@ public static class TemplateGenerator continue; var ctTypeName = GetTypeName(c.ValueType, templates); - rt.AppendLine($"public const {ctTypeName} {c.Name} = {c.Value};"); + rt.AppendLine($"[Public] public const {ctTypeName} {c.Name} = {c.Value};"); } @@ -360,7 +360,7 @@ public static class TemplateGenerator { var etTypeName = GetTypeName(e.ArgumentType, templates); rt.AppendLine($"case {e.Index}: {e.Name}?.Invoke(({etTypeName})args); break;"); - eventsList.AppendLine($"public event ResourceEventHandler<{etTypeName}> {e.Name};"); + eventsList.AppendLine($"[Public] public event ResourceEventHandler<{etTypeName}> {e.Name};"); } rt.AppendLine("}}"); diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Resource/Template/TypeTemplate.cs index 8a14129..468a41b 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Resource/Template/TypeTemplate.cs @@ -205,7 +205,7 @@ public class TypeTemplate return rt.ToArray(); } } - + return new Type[0]; } @@ -436,7 +436,14 @@ public class TypeTemplate var addProperty = (PropertyInfo pi, PublicAttribute publicAttr) => { - var propType = RepresentationType.FromType(pi.PropertyType);//, nullableAttr != null && nullableAttr.Flag == 2); + + var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null; + + var propType = genericPropType == typeof(DistributedPropertyContext<>) ? + RepresentationType.FromType(pi.PropertyType.GetGenericArguments()[0]) : + RepresentationType.FromType(pi.PropertyType); + + //var propType = RepresentationType.FromType(pi.PropertyType);//, nullableAttr != null && nullableAttr.Flag == 2); if (propType == null) throw new Exception($"Unsupported type `{pi.PropertyType}` in property `{type.Name}.{pi.Name}`"); @@ -449,6 +456,9 @@ public class TypeTemplate var flags = nullableAttr?.Flags?.ToList() ?? new List(); + if (flags.Count > 0 && genericPropType == typeof(DistributedPropertyContext<>)) + flags.RemoveAt(0); + if (nullableContextAttr?.Flag == 2) { if (flags.Count == 1) @@ -537,8 +547,11 @@ public class TypeTemplate var addFunction = (MethodInfo mi, PublicAttribute publicAttr) => { + var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null; - var rtType = RepresentationType.FromType(mi.ReturnType); + var rtType = genericRtType == typeof(AsyncReply<>) ? + RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) : + RepresentationType.FromType(mi.ReturnType); if (rtType == null) throw new Exception($"Unsupported type `{mi.ReturnType}` in method `{type.Name}.{mi.Name}` return"); @@ -557,8 +570,8 @@ public class TypeTemplate var rtFlags = rtNullableAttr?.Flags?.ToList() ?? new List(); - - + if (rtFlags.Count > 0 && genericRtType == typeof(AsyncReply<>)) + rtFlags.RemoveAt(0); if (rtNullableContextAttr?.Flag == 2) { @@ -673,7 +686,8 @@ public class TypeTemplate } } - if (templateType == TemplateType.Resource) + if (templateType == TemplateType.Resource + || templateType == TemplateType.Wrapper) { foreach (var ei in eventsInfo) @@ -730,7 +744,8 @@ public class TypeTemplate } } - if (templateType == TemplateType.Resource) + if (templateType == TemplateType.Resource + || templateType == TemplateType.Wrapper) { foreach (var ei in eventsInfo) @@ -792,7 +807,7 @@ public class TypeTemplate var parentId = GetTypeGuid(ParentDefinedType); b.AddGuid(parentId); } - + if (hasClassAnnotation) { var classAnnotationBytes = DC.ToBytes(classAnnotation.Annotation); @@ -934,7 +949,7 @@ public class TypeTemplate else if (type == 1) // property { - string readAnnotation = null, writeAnnotation= null; + string readAnnotation = null, writeAnnotation = null; var hasReadAnnotation = ((data[offset] & 0x8) == 0x8); var hasWriteAnnotation = ((data[offset] & 0x10) == 0x10); diff --git a/Test/MyService.cs b/Test/MyService.cs index 439597b..c258976 100644 --- a/Test/MyService.cs +++ b/Test/MyService.cs @@ -149,6 +149,14 @@ public partial class MyService return new Random().NextDouble(); } + + [Public] public AsyncReply?>> AsyncHello() + { + var rt = new List?>(); + rt.Add(new Map() { [1] = "SSSSS", [2] = null }); + return new AsyncReply?>>(rt); + } + [Public] public void Connection(object a1, int a2, DistributedConnection a3) => Console.WriteLine($"VoidArgs {a1} {a2} {a3}"); diff --git a/Test/Program.cs b/Test/Program.cs index dd97b9b..b7dc888 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -106,6 +106,7 @@ namespace Test var opt = await remote.Optional(new { a1 = 22, a2 = 33, a4 = "What?" }); Console.WriteLine(opt); + var hello = await remote.AsyncHello(); await remote.Void(); await remote.Connection("ss", 33);