Пример #1
0
        public RpcMethodInfo(RpcMethodInfo methodInfo, int parametersCount)
        {
            Method          = methodInfo.Method;
            ParametersCount = parametersCount;
            ParamsCount     = methodInfo.ParametersCount;
            ReturnType      = methodInfo.ReturnType;

            Parameters = new RpcTypeInfo[parametersCount];

            var count = methodInfo.HasDefaultValue ? parametersCount : ParamsCount - 1;

            for (int i = 0; i < count; i++)
            {
                Parameters[i] = methodInfo.Parameters[i];
            }

            if (methodInfo.HasDefaultValue)
            {
                HasDefaultValue    = true;
                FirstDefaultParams = methodInfo.FirstDefaultParams;
                return;
            }

            HasParams   = true;
            TypeParams  = methodInfo.TypeParams;
            ElementType = methodInfo.ElementType;

            var rpcTypeInfo = InformationOnTheTypes.GetTypeInformation(methodInfo.TypeParams);

            for (int i = ParamsCount - 1; i < parametersCount; i++)
            {
                Parameters[i] = rpcTypeInfo;
            }
        }
 public static RpcTypeInfo GetTypeInformation(Type type)
 {
     if (!TypeInfos.TryGetValue(type, out var rpcTypeInfo))
     {
         rpcTypeInfo     = new RpcTypeInfo(type);
         TypeInfos[type] = rpcTypeInfo;
     }
     return(rpcTypeInfo);
 }
Пример #3
0
        public RpcMethodInfo(MethodInfo methodInfo)
        {
            Method = methodInfo;

            ParameterInfo[] parameters = Method.GetParameters();
            HasParams       = false;
            ParametersCount = parameters.Length;
            ParamsCount     = 0;
            if (ParametersCount > 0)
            {
                HasParams = parameters[parameters.Length - 1].GetCustomAttributes(typeof(ParamArrayAttribute), false).GetEnumerator().MoveNext();
            }

            if (HasParams)
            {
                TypeParams  = parameters[parameters.Length - 1].ParameterType.GetElementType();
                ElementType = InformationOnTheTypes.GetTypeInformation(TypeParams);
            }

            Parameters = new RpcTypeInfo[ParametersCount];

            for (int i = 0; i < parameters.Length; i++)
            {
                var param = parameters[i];
                Parameters[i] = InformationOnTheTypes.GetTypeInformation(param.ParameterType);

                if (!HasDefaultValue && param.HasDefaultValue)
                {
                    HasDefaultValue = true;

                    FirstDefaultParams = i;
                }
            }

            IsGeneric = methodInfo.IsGenericMethod && methodInfo.IsGenericMethodDefinition;

            if (IsGeneric)
            {
                GenericMethod = new GenericMethodData(Method, Parameters);
            }
            ReturnType = methodInfo.ReturnType.GetTypeInfo().IsInterface ? methodInfo.ReturnType : null;
        }
Пример #4
0
        private bool CompareParam(Type parameter, RpcTypeInfo rpcParameter)
        {
            var  rpcParameterType = rpcParameter.Type;
            bool isSuit           = false;

            if (rpcParameter.IsGenericType)
            {
                isSuit = parameter.GetTypeInfo().IsGenericType
                    ? parameter.IsGenericTypeOf(rpcParameterType.GetTypeInfo(), rpcParameterType)
                    : IsSuit(rpcParameterType, parameter);
            }
            else
            {
                isSuit = rpcParameter.IsEqual(parameter);
            }
            if (!isSuit)
            {
                return(false);
            }

            return(true);
        }