mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-29 23:21:36 +00:00 
			
		
		
		
	invoke
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
| using System.Xml.Linq; | ||||
|  | ||||
| namespace Esiur.Resource; | ||||
|  | ||||
| @@ -8,10 +9,29 @@ namespace Esiur.Resource; | ||||
|  | ||||
| public class ExportAttribute : Attribute | ||||
| { | ||||
|     public string Name { get; set; } | ||||
|     public string Name { get; private set; } = null; | ||||
|     public Type ReturnType { get; private set; } = null; | ||||
|  | ||||
|     public ExportAttribute(string name = null) | ||||
|     public ExportAttribute() | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public ExportAttribute(string name) | ||||
|     { | ||||
|         Name = name; | ||||
|     } | ||||
|  | ||||
|     public ExportAttribute(Type returnType) | ||||
|     { | ||||
|         ReturnType = returnType; | ||||
|     } | ||||
|  | ||||
|     public ExportAttribute(string name, Type returnType) | ||||
|     { | ||||
|         Name = name; | ||||
|         ReturnType = returnType; | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -66,8 +66,8 @@ public class FunctionTemplate : MemberTemplate | ||||
|         return bl.ToArray(); | ||||
|     } | ||||
|  | ||||
|      public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, RepresentationType returnType, string annotation = null) | ||||
|         : base(template, index, name, inherited) | ||||
|     public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, RepresentationType returnType, string annotation = null) | ||||
|        : base(template, index, name, inherited) | ||||
|     { | ||||
|         this.Arguments = arguments; | ||||
|         this.ReturnType = returnType; | ||||
| @@ -82,9 +82,25 @@ public class FunctionTemplate : MemberTemplate | ||||
|  | ||||
|         var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null; | ||||
|  | ||||
|         var rtType = genericRtType == typeof(AsyncReply<>) ? | ||||
|                 RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) : | ||||
|                 RepresentationType.FromType(mi.ReturnType); | ||||
|         RepresentationType rtType; | ||||
|  | ||||
|         if (genericRtType == typeof(AsyncReply<>)) | ||||
|         { | ||||
|             rtType = RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]); | ||||
|         } | ||||
|         else if (genericRtType == typeof(IEnumerable<>) || genericRtType == typeof(IAsyncEnumerable<>)) | ||||
|         { | ||||
|             // get export | ||||
|             rtType = RepresentationType.FromType(mi.GetCustomAttribute<ExportAttribute>()?.ReturnType ?? typeof(object)); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             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"); | ||||
| @@ -106,7 +122,7 @@ public class FunctionTemplate : MemberTemplate | ||||
|         //var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(NullableAttribute), true).FirstOrDefault() as NullableAttribute; | ||||
|         var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); | ||||
|  | ||||
|   | ||||
|  | ||||
|  | ||||
|         // var rtNullableContextAttr = mi.ReturnTypeCustomAttributes | ||||
|         //                                .GetCustomAttributes(typeof(NullableContextAttribute), true) | ||||
| @@ -115,7 +131,7 @@ public class FunctionTemplate : MemberTemplate | ||||
|  | ||||
|  | ||||
|         var rtNullableContextAttr = mi.ReturnTypeCustomAttributes | ||||
|                                 .GetCustomAttributes(true).FirstOrDefault(x=>x.GetType().Name == "NullableContextAttribute") | ||||
|                                 .GetCustomAttributes(true).FirstOrDefault(x => x.GetType().Name == "NullableContextAttribute") | ||||
|                                 ?? nullableContextAttr; | ||||
|  | ||||
|         var rtNullableAttrFlags = (rtNullableAttr?.GetType().GetField("NullableFlags")?.GetValue(rtNullableAttr) as byte[] ?? new byte[0]).ToList(); | ||||
| @@ -164,7 +180,7 @@ public class FunctionTemplate : MemberTemplate | ||||
|  | ||||
|             var argNullableAttr = x.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute"); | ||||
|             var argNullableContextAttr = x.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableContextAttr"); | ||||
|   | ||||
|  | ||||
|             //var argFlags = argNullableAttr?.Flags?.ToList() ?? new List<byte>(); | ||||
|             //var argFlags = ((byte[])argNullableAttr?.NullableFlags ?? new byte[0]).ToList(); | ||||
|  | ||||
| @@ -196,7 +212,7 @@ public class FunctionTemplate : MemberTemplate | ||||
|         }) | ||||
|         .ToArray(); | ||||
|  | ||||
|         var fn =  customName ?? mi.Name; | ||||
|         var fn = customName ?? mi.Name; | ||||
|  | ||||
|         var ft = new FunctionTemplate(typeTemplate, index, fn, mi.DeclaringType != type, | ||||
|             mi.IsStatic, | ||||
|   | ||||
| @@ -16,10 +16,14 @@ public class MemberData | ||||
|     public MemberData? Parent; | ||||
|     public MemberData? Child; | ||||
|     public byte Index; | ||||
|     //public ExportAttribute ExportAttribute; | ||||
|  | ||||
|     public MemberData(string name, MemberInfo info, int order) | ||||
|  | ||||
|     //public string Name => ExportAttribute?.Name ?? Info.Name; | ||||
|  | ||||
|     public MemberData(MemberInfo info, int order) | ||||
|     { | ||||
|         this.Name = name; | ||||
|         this.Name = info.GetCustomAttribute<ExportAttribute>()?.Name ?? info.Name; | ||||
|         this.Info = info; | ||||
|         this.Order = order; | ||||
|     } | ||||
|   | ||||
| @@ -611,7 +611,6 @@ public class TypeTemplate | ||||
|                              ) | ||||
|                           )) | ||||
|                     .Select(x => new MemberData( | ||||
|                         name: x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name, | ||||
|                         info: x, | ||||
|                         order: order | ||||
|                     )) | ||||
| @@ -631,7 +630,6 @@ public class TypeTemplate | ||||
|                     .Where(x => x.GetCustomAttribute<ExportAttribute>() != null) | ||||
|                     .Where(x => !(x is MethodInfo m && m.IsSpecialName)) | ||||
|                     .Select(x => new MemberData ( | ||||
|                         name : x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name, | ||||
|                         info : x, | ||||
|                         order : order | ||||
|                     )) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user