Esempio n. 1
0
        public Helper_API_Method[] Methods(string classname)
        {
            string   assemblyName  = "Song.ViewData";
            string   classFullName = String.Format("{0}.Methods.{1}", assemblyName, classname);
            Assembly assembly      = Assembly.Load(assemblyName);
            //当前类的反射对象
            Type classtype = null;

            foreach (Type info in assembly.GetExportedTypes())
            {
                if (info.FullName.Equals(classFullName, StringComparison.CurrentCultureIgnoreCase))
                {
                    classtype = info;
                    break;
                }
            }
            //注释文档
            XmlNodeList nodes = readXml();
            //类下面的方法,仅获取当前类生成的方法,不包括父类
            List <Helper_API_Method> list = new List <Helper_API_Method>();

            MemberInfo[] mis = classtype.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
            foreach (MethodInfo mi in mis)
            {
                string fullname = Helper_API_Method.GetFullName(mi);        //带参数的方法名称
                //方法的注释
                XmlNode node = Helper_API_Method.GetNode(mi, nodes);
                list.Add(new Helper_API_Method()
                {
                    Name      = mi.Name,
                    FullName  = fullname,
                    Paras     = Helper_API_Method_Para.GetParas(mi, node),
                    Return    = Helper_API_Method_Return.GetReturn(mi, node),
                    ClassName = mi.DeclaringType.Name,
                    Class     = mi.DeclaringType.FullName,
                    Intro     = Helper_API_Method.GetHelp(node, "summary"),
                    Remarks   = Helper_API_Method.GetHelp(node, "remarks"),
                    Example   = Helper_API_Method.GetHelp(node, "example"),
                    Attrs     = Helper_API_Method_Attr.GetAttrs(mi)
                });
            }
            //按方法名排序
            list.Sort((a, b) => a.Name.CompareTo(b.Name));
            return(list.ToArray <Helper_API_Method>());
        }
Esempio n. 2
0
        }                                  //缓存的过期时效
        public static Helper_API_Method_Attr[] GetAttrs(MethodInfo method)
        {
            //所有特性
            Type[]            attrs = WebAttribute.Initialization();
            List <WeishaAttr> list  = new List <WeishaAttr>();

            foreach (Type att in attrs)
            {
                //取类上面的特性
                object[] attrsObj = method.DeclaringType.GetCustomAttributes(att, true);
                for (int i = 0; i < attrsObj.Length; i++)
                {
                    WeishaAttr attr = attrsObj[i] as WeishaAttr;
                    if (list.Contains(attr))
                    {
                        if (attr.Ignore)
                        {
                            list[i].Ignore = true;
                        }
                    }
                    else
                    {
                        list.Add(attr);
                    }
                }
                //取方法上的特性
                object[] attrsMethod = method.GetCustomAttributes(att, true);
                for (int i = 0; i < attrsMethod.Length; i++)
                {
                    WeishaAttr attr = attrsMethod[i] as WeishaAttr;
                    if (list.Contains(attr))
                    {
                        if (attr.Ignore)
                        {
                            list[i].Ignore = true;
                        }
                    }
                    else
                    {
                        list.Add(attr);
                    }
                }
            }
            //ignore为true的全部移除,不输出
            for (int i = 0; i < list.Count; i++)
            {
                WeishaAttr attr = list[i] as WeishaAttr;
                if (attr == null)
                {
                    continue;
                }
                if (attr.Ignore)
                {
                    list.RemoveAt(i);
                }
            }
            //去除"Attribute"字样
            Helper_API_Method_Attr[] arr = new Helper_API_Method_Attr[list.Count];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i]      = new Helper_API_Method_Attr();
                arr[i].Name = list[i].GetType().Name.Replace("Attribute", "");
                if (list[i] is WeishaAttr)
                {
                    arr[i].Ignore = ((WeishaAttr)list[i]).Ignore;
                }
                if (list[i] is CacheAttribute)
                {
                    arr[i].Expires = ((CacheAttribute)list[i]).Expires;
                }
            }
            return(arr);
        }