Exemplo 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>());
        }
Exemplo n.º 2
0
        public static Helper_API_Method_Return GetReturn(MethodInfo method, XmlNode node)
        {
            Helper_API_Method_Return ret = new Helper_API_Method_Return();

            if (node != null)
            {
                if (node.SelectSingleNode("returns") != null)
                {
                    ret.Intro = node.SelectSingleNode("returns").InnerText.Trim();   //返回值的摘要
                }
            }
            if (string.IsNullOrWhiteSpace(ret.Intro))
            {
                ret.Intro = string.Empty;
            }
            ret.Type = method.ReturnParameter.ToString();      //返回类型
            return(ret);
        }
Exemplo n.º 3
0
        public static Helper_API_Method_Return GetReturn(MethodInfo method, XmlNode node)
        {
            Helper_API_Method_Return ret = new Helper_API_Method_Return();

            if (node != null)
            {
                if (node.SelectSingleNode("returns") != null)
                {
                    ret.Intro = node.SelectSingleNode("returns").InnerText.Trim();   //返回值的摘要
                }
            }
            if (string.IsNullOrWhiteSpace(ret.Intro))
            {
                ret.Intro = string.Empty;
            }
            Type nullableType = System.Nullable.GetUnderlyingType(method.ReturnParameter.ParameterType);

            ret.Type     = nullableType != null ? nullableType.FullName + "?" : method.ReturnParameter.ToString();
            ret.Nullable = nullableType != null;
            return(ret);
        }