Exemplo n.º 1
0
        private static Type[] FindType(Type[] types, Type extendedType, string methodName, Func <MethodInfo, bool> filter = null)
        {
            var query = from type in types
                        let typeInfo = type.GetTypeInfo()
                                       where typeInfo.IsSealed && typeInfo.IsAbstract
                                       let synonym = InformationOnTheTypes.GetMethodNameBySynonym(type, methodName)
                                                     from method in typeInfo.GetMethods()
                                                     where method.IsStatic && method.IsDefined(typeof(ExtensionAttribute), false) &&
                                                     method.Name == synonym && (filter?.Invoke(method) ?? true)
                                                     let parameterType = method.GetParameters()[0].ParameterType
                                                                         where (parameterType.IsAssignableFrom(extendedType) ||
                                                                                GenericMethodData.IsSuit(parameterType, extendedType))
                                                                         select type;

            return(query.Distinct().ToArray());
        }
Exemplo n.º 2
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;
        }