mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-31 16:01:34 +00:00 
			
		
		
		
	Runtime types
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
|     <Copyright>Ahmed Kh. Zamil</Copyright> | ||||
|      <PackageProjectUrl>http://www.esiur.com</PackageProjectUrl> | ||||
|     <GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||||
|     <Version>2.2.3</Version> | ||||
|     <Version>2.2.4.4</Version> | ||||
|     <RepositoryUrl>https://github.com/esiur/esiur-dotnet</RepositoryUrl> | ||||
|     <Authors>Ahmed Kh. Zamil</Authors> | ||||
|     <AssemblyVersion></AssemblyVersion> | ||||
|   | ||||
| @@ -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("}}"); | ||||
|   | ||||
| @@ -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<byte>(); | ||||
|  | ||||
|             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<byte>(); | ||||
|  | ||||
|  | ||||
|  | ||||
|             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); | ||||
|   | ||||
| @@ -149,6 +149,14 @@ public partial class MyService | ||||
|         return new Random().NextDouble(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     [Public] public AsyncReply<List<Map<int, string?>?>> AsyncHello() | ||||
|     { | ||||
|         var rt = new List<Map<int, string?>?>(); | ||||
|         rt.Add(new Map<int, string?>() { [1] = "SSSSS", [2] = null }); | ||||
|         return new AsyncReply<List<Map<int, string?>?>>(rt); | ||||
|     } | ||||
|  | ||||
|     [Public] | ||||
|     public void Connection(object a1, int a2, DistributedConnection a3) => | ||||
|         Console.WriteLine($"VoidArgs {a1} {a2} {a3}"); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user