Exemple #1
0
        /// <summary>
        /// GetAllMethods 获取接口的所有方法信息,包括继承的
        /// </summary>
        public static IList <MethodInfo> GetAllMethods(params Type[] interfaceTypes)
        {
            foreach (Type interfaceType in interfaceTypes)
            {
                if (!interfaceType.IsInterface)
                {
                    throw new Exception("Target Type must be interface!");
                }
            }

            IList <MethodInfo> list = new List <MethodInfo>();

            foreach (Type interfaceType in interfaceTypes)
            {
                ReflectionHelper.DistillMethods(interfaceType, ref list);
            }

            return(list);
        }
Exemple #2
0
        private static void DistillMethods(Type interfaceType, ref IList <MethodInfo> methodList)
        {
            foreach (MethodInfo meth in interfaceType.GetMethods())
            {
                bool isExist = false;
                foreach (MethodInfo temp in methodList)
                {
                    if ((temp.Name == meth.Name) && (temp.ReturnType == meth.ReturnType))
                    {
                        ParameterInfo[] para1 = temp.GetParameters();
                        ParameterInfo[] para2 = meth.GetParameters();
                        if (para1.Length == para2.Length)
                        {
                            bool same = true;
                            for (int i = 0; i < para1.Length; i++)
                            {
                                if (para1[i].ParameterType != para2[i].ParameterType)
                                {
                                    same = false;
                                }
                            }

                            if (same)
                            {
                                isExist = true;
                                break;
                            }
                        }
                    }
                }

                if (!isExist)
                {
                    methodList.Add(meth);
                }
            }

            foreach (Type superInterfaceType in interfaceType.GetInterfaces())
            {
                ReflectionHelper.DistillMethods(superInterfaceType, ref methodList);
            }
        }