Beispiel #1
0
        public static IDictionary <string, RpcMetadata> ScanRpcMetadatas(this Assembly[] assembly, bool isGenerateReflector, Func <Type, string> getKey, Func <Type, bool> predicate)
        {
            var metadatas = new Dictionary <string, RpcMetadata>();

            foreach (var item in assembly.SelectMany(i => i.GetExportedTypes().Where(predicate)).Distinct())
            {
                var reflector = item.GetReflector();
                if (!reflector.IsDefined <CodecAttribute>())
                {
                    throw new Exception($"{item.FullName} no CodecAttribute.");
                }

                var metadata = new RpcMetadata()
                {
                    InterfaceType = item,
                    Servant       = getKey(item),
                    CodecType     = reflector.GetCustomAttribute <CodecAttribute>().GetType(),
                    Methods       = new Dictionary <string, RpcMethodMetadata>(StringComparer.OrdinalIgnoreCase)
                };
                SetMethodMetaDatas(metadata, isGenerateReflector);
                metadatas.Add(metadata.Servant, metadata);
            }

            return(metadatas);
        }
Beispiel #2
0
 private static void SetMethodMetaDatas(RpcMetadata metadata, bool isGenerateReflector)
 {
     foreach (var method in metadata.InterfaceType.GetMethods())
     {
         var returnInfo = method.ReturnType.GetTypeInfo();
         var m          = new RpcMethodMetadata()
         {
             DisplayName      = method.GetReflector().DisplayName,
             Name             = HandleFuncName(method.Name),
             ReturnInfo       = method.ReturnParameter,
             Parameters       = method.GetParameters(),
             MethodInfo       = method,
             Reflector        = isGenerateReflector ? method.GetReflector() : null,
             InvokeStatus     = GetMethodInvokeStatus(method, returnInfo),
             IsValueTask      = returnInfo.IsValueTask(),
             IsTaskWithResult = returnInfo.IsTaskWithResult(),
             IsTask           = returnInfo.IsTask(),
         };
         var testName = method.GetReflector().DisplayName;
         SetConvertReturnType(returnInfo, m);
         metadata.Methods.Add(m.DisplayName, m);
     }
 }
Beispiel #3
0
 public bool TryGetValue(string servantName, out RpcMetadata metadata)
 {
     return(metadatas.TryGetValue(servantName, out metadata));
 }