public AllMethodsForName(IEnumerable <MethodInfo> methods)
        {
            foreach (var method in methods)
            {
                var methodInfo = new RpcMethodInfo(method);

                if (methodInfo.HasParams || methodInfo.HasDefaultValue)
                {
                    _methodsParams.Add(methodInfo);
                    var commonMethod = new RpcMethodInfo(methodInfo);
                    AddMethod(commonMethod, commonMethod.ParametersCount);
                }
                else
                {
                    if (MaxParamCount < methodInfo.ParametersCount)
                    {
                        MaxParamCount = methodInfo.ParametersCount;
                    }

                    AddMethod(methodInfo, methodInfo.ParametersCount);
                }
            }

            AddParamsMethodToCommon();

            if (_methodsParams.Any())
            {
                _methodsParams.Sort(new CompareMethodsParams());
                if (MaxParamCount < 16)
                {
                    MaxParamCount = 16;
                }
            }
        }
Exemplo n.º 2
0
        private bool ExecuteInterfaceMethodAsObject(string name, object[] args, out object result, ref string Error)
        {
            result = null;
            Error  = null;
            if (!(IsType || Type.GetTypeInfo().IsInterface))
            {
                return(false);
            }

            RpcMethodInfo method = InformationOnTheTypes.FindMethod(Object.GetType(), false, name, args);

            if (method == null)
            {
                return(false);
            }

            try
            {
                result = method.ExecuteMethod(Object, args);
                return(true);
            }
            catch (Exception e)
            {
                Error += GetExceptionString("методе", name, e);
            }
            return(false);
        }
Exemplo n.º 3
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 RpcMethodInfo FindMethod(bool isStatic, object[] parametersObjects)
        {
            var parameters = GetTypesParameters(parametersObjects);

            if (_commonMethods.TryGetValue(parameters.Length, out var methodsList))
            {
                if (parameters.Length == 0)
                {
                    var method = methodsList[0];
                    if (!method.IsGeneric && isStatic == method.Method.IsStatic)
                    {
                        return(method);
                    }

                    return(null);
                }

                foreach (var method in methodsList)
                {
                    if (!method.IsGeneric && isStatic == method.Method.IsStatic && method.Compare(parameters))
                    {
                        return(method);
                    }
                }
            }

            foreach (var method in _methodsParams)
            {
                if (!method.IsGeneric && isStatic == method.Method.IsStatic && method.CompareParams(parameters))
                {
                    return(method);
                }

                if (method.IsGeneric && isStatic == method.Method.IsStatic)
                {
                    var methodInfo = method.GenericMethod.GetRealMethodsParams(parameters, method);
                    var res        = new RpcMethodInfo(methodInfo);

                    if (res.CompareParams(parameters))
                    {
                        return(res);
                    }
                }
            }

            if (methodsList != null)
            {
                var res = FindGenericMethod(isStatic, methodsList, parameters);
                if (res != null)
                {
                    return(res);
                }
            }

            // AutoWrap.СообщитьОбОшибке("Метод существует но не подходят parametersObjects");
            return(null);
        }
Exemplo n.º 5
0
 // Добавить парамс как обычный метод
 public RpcMethodInfo(RpcMethodInfo methodInfo)
 {
     Method          = methodInfo.Method;
     ParametersCount = methodInfo.ParametersCount;
     ParamsCount     = 0;
     HasParams       = false;
     HasDefaultValue = false;
     ReturnType      = methodInfo.ReturnType;
     Parameters      = methodInfo.Parameters;
 }
        private void AddMethod(RpcMethodInfo methodInfo, int parametersCount)
        {
            if (!_commonMethods.TryGetValue(parametersCount, out var methodList))
            {
                methodList = new List <RpcMethodInfo>();
                _commonMethods[parametersCount] = methodList;
            }

            methodList.Add(methodInfo);
        }
        public RpcMethodInfo FindGenericMethod(bool isStatic, List <RpcMethodInfo> methodsList, Type[] parameters)
        {
            foreach (var method in methodsList)
            {
                if (method.IsGeneric && isStatic == method.Method.IsStatic)
                {
                    var methodInfo = method.GenericMethod.GetRealMethod(parameters);

                    if (methodInfo != null)
                    {
                        var res = new RpcMethodInfo(methodInfo);
                        if (res.Compare(parameters))
                        {
                            return(res);
                        }
                    }
                }
            }

            return(null);
        }
        public RpcMethodInfo FindGenericMethod(bool isStatic, Type[] genericParameters, Type[] methodParameters)
        {
            if (_commonMethods.TryGetValue(methodParameters.Length, out var methodList))
            {
                foreach (var method in methodList)
                {
                    if (method.IsGeneric && isStatic == method.Method.IsStatic)
                    {
                        // var MethodInfo = метод.GenericMethod.GetRealMethod(genericParameters, methodParameters);
                        var methodInfo = method.GenericMethod.MethodInfo.MakeGenericMethod(genericParameters);
                        {
                            var res = new RpcMethodInfo(methodInfo);
                            if (res.Compare(methodParameters))
                            {
                                return(res);
                            }
                        }
                    }
                }
            }

            foreach (var method in _methodsParams)
            {
                if (method.IsGeneric && isStatic == method.Method.IsStatic)
                {
                    var methodInfo = method.GenericMethod.MethodInfo.MakeGenericMethod(genericParameters);// метод.GenericMethod.GetRealMethod(genericParameters, methodParameters);
                    {
                        var res = new RpcMethodInfo(methodInfo);
                        if (res.CompareParams(methodParameters))
                        {
                            return(res);
                        }
                    }
                }
            }

            return(null);
        }
        public MethodInfo GetRealMethodsParams(Type[] parameters, RpcMethodInfo rpcMethodInfo)
        {
            if (!_canPrint)
            {
                return(null);
            }

            if (rpcMethodInfo.HasDefaultValue)
            {
                if ((parameters.Length < rpcMethodInfo.FirstDefaultParams) || parameters.Length > rpcMethodInfo.ParametersCount)
                {
                    return(null);
                }
            }

            int length = Math.Min(_rpcParameters.Length, parameters.Length);

            if (rpcMethodInfo.HasParams)
            {
                length = rpcMethodInfo.ParametersCount - 1;
                if (parameters.Length >= rpcMethodInfo.ParametersCount)
                {
                    if (!CompareParam(parameters[parameters.Length - 1], rpcMethodInfo.ElementType))
                    {
                        return(null);
                    }
                }
            }

            // Сравним parameters без вывода
            for (var i = 0; i < length; i++)
            {
                var parameter    = parameters[i];
                var rpcParameter = _rpcParameters[i];

                if (!CompareParam(parameter, rpcParameter))
                {
                    return(null);
                }
            }

            var realTypeArguments = new Type[_genericArguments.Length];

            for (var i = 0; i < _genericArguments.Length; i++)
            {
                var argument   = _genericArguments[i];
                var outIndexes = _outParameters[i];

                foreach (var index in outIndexes)
                {
                    var realType = GetRealType(argument, _rpcParameters[index].Type, parameters[index]);

                    if (realType != null)
                    {
                        if (realTypeArguments[i] != null && realTypeArguments[i] != realType)
                        {
                            return(null);
                        }
                        realTypeArguments[i] = realType;
                    }
                }
                if (realTypeArguments[i] == null)
                {
                    return(null);
                }
            }
            try
            {
                return(MethodInfo.MakeGenericMethod(realTypeArguments));;
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        private void AddParamsToList(KeyValuePair <int, List <RpcMethodInfo> >[] valueArray, RpcMethodInfo methodInfo)
        {
            int minCount = methodInfo.HasDefaultValue ? methodInfo.FirstDefaultParams : methodInfo.ParametersCount - 1;

            foreach (var keyValuePair in valueArray)
            {
                if (keyValuePair.Key < minCount)
                {
                    continue;
                }

                if (!(methodInfo.HasDefaultValue && keyValuePair.Key >= methodInfo.ParametersCount))
                {
                    keyValuePair.Value.Add(new RpcMethodInfo(methodInfo, keyValuePair.Key));
                }
            }
        }