Esempio n. 1
0
 /// <summary>
 /// 获取服务信息
 /// </summary>
 /// <param name="type">服务类型</param>
 /// <returns>服务信息</returns>
 public void AddServiceInfo(Type type)
 {
     if (_serviceInfos.ContainsKey(type.Name))
     {
         throw new RpcInternalException($"The type {type} has registed.");
     }
     _serviceInfos.Add(type.Name, ServiceReflectionInfo.GetServiceInfo(type));
 }
Esempio n. 2
0
        /// <summary>
        /// 获取服务信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ServiceReflectionInfo GetServiceInfo(Type type)
        {
            var info = new ServiceReflectionInfo()
            {
                ServiceType = type, Attributes = type.GetCustomAttributes().ToList()
            };
            var methods        = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
            var methodInfoList = new List <MethodReflectionInfo>();

            foreach (var method in methods)
            {
                var mInfo = new MethodReflectionInfo()
                {
                    Attributes  = method.GetCustomAttributes().ToList(),
                    Method      = method,
                    Parameters  = method.GetParameters(),
                    ReturnType  = method.ReturnType,
                    IsAwaitable = method.ReturnType.GetMethod(nameof(Task.GetAwaiter)) != null
                };
                methodInfoList.Add(mInfo);
            }
            info.Methods = methodInfoList;
            return(info);
        }
Esempio n. 3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="clientStub"></param>
 /// <param name="serviceType"></param>
 internal AbstractClient(ClientStub clientStub, Type serviceType)
 {
     _clientStub  = clientStub;
     _serviceInfo = _clientStub.GetOrSetServiceInfo(serviceType);
 }