Ejemplo n.º 1
0
        /// <summary>
        /// 获取参数列表
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="returnValue"></param>
        /// <returns></returns>
        private List <SolidWorksApiParameter> GetParams(IHtmlDocument doc, ref SolidWorksApiParameter returnValue)
        {
            List <SolidWorksApiParameter> SWParams = new List <SolidWorksApiParameter>();
            var syntaxNode = doc.QuerySelectorAll("div").Where(p => p.Id == "syntaxSection").Select(p => p).Single();

            if (syntaxNode != null)
            {
                //查询语法节点
                var ParamNodeEnum = syntaxNode.Children.Where(p => p.InnerHtml == "Parameters").Select(p => p);
                if (ParamNodeEnum != null && ParamNodeEnum.Count() > 0)
                {
                    var ParamNode = ParamNodeEnum.Single();
                    var h4Params  = ParamNode.NextElementSibling;
                    if (h4Params != null)
                    {
                        foreach (var item in h4Params.Children)
                        {
                            if (item.NodeName.ToLower() == "dt")
                            {
                                //构建参数列表
                                string name       = (item.Children != null && item.Children.Length > 0)? item.Children[0].InnerHtml : string.Empty;
                                string ParamValue = string.Empty;
                                if (item.NextElementSibling != null)
                                {
                                    ParamValue = item.NextElementSibling.TextContent;
                                }
                                SolidWorksApiParameter apiParam = new SolidWorksApiParameter(name, ParamValue);
                                SWParams.Add(apiParam);
                            }
                        }
                        //元素后的节点为返回值
                        //返回值
                        var ReturnNode = h4Params.NextElementSibling;
                        if (ReturnNode != null && ReturnNode.InnerHtml.Trim() == "Return Value")
                        {
                            returnValue = new SolidWorksApiParameter("Return Value", ReturnNode.NextElementSibling != null ? ReturnNode.NextElementSibling.TextContent : string.Empty);
                        }
                    }
                }
                else
                {
                    //只有返回值
                    var ReturnNodeEnum = syntaxNode.Children.Where(p => (p.NodeName.ToLower() == "h4" && p.InnerHtml == "Return Value")).Select(p => p);
                    if (ReturnNodeEnum != null && ReturnNodeEnum.Count() > 0)
                    {
                        var ReturnNode = ReturnNodeEnum.Single();
                        if (ReturnNode != null && ReturnNode.InnerHtml.Trim() == "Return Value")
                        {
                            returnValue = new SolidWorksApiParameter("Return Value", ReturnNode.NextElementSibling != null ? ReturnNode.NextElementSibling.TextContent : string.Empty);
                        }
                    }
                }
            }
            if (SWParams.Count == 0)
            {
                SWParams = null;
            }
            return(SWParams);
        }
Ejemplo n.º 2
0
        private object GetMethodOrProertyOrEnumObj(string fileStr, string filePath, out DocType thisDocType)
        {
            thisDocType = DocType.NotKonw;
            try
            {
                //获取文档
                var doc = GetAngleSharpDoc(fileStr);
                //获取文档类型
                thisDocType = GetDocType(doc);

                if (thisDocType == DocType.NotKonw)
                {
                    Debug.Print("无效文件" + fileStr);
                    return(null);
                }
                if (filePath.Contains("SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISimulation~Animation.html"))
                {
                    //string a = "5";
                }
                //获取评论信息
                string Remark = GetRemark(doc);
                //获取描述
                string Description = GetDescription(doc);
                //获取可用版本信息
                string aviablity = GetAvailability(doc);

                if (thisDocType == DocType.Property)
                {
                    return(new SolidWorksApiPropertyModel(Path.GetFileNameWithoutExtension(filePath), Description, Remark, aviablity));
                }

                if (thisDocType == DocType.Method)
                {
                    SolidWorksApiParameter        ReturnValue = null;
                    List <SolidWorksApiParameter> SWParam     = GetParams(doc, ref ReturnValue);

                    return(new SolidWorksApiMethodModel(Path.GetFileNameWithoutExtension(filePath), Description, Remark, aviablity, SWParam, ReturnValue));
                }

                if (thisDocType == DocType.Delegate)
                {
                    SolidWorksApiParameter        ReturnValue = null;
                    List <SolidWorksApiParameter> SWParam     = GetParams(doc, ref ReturnValue);

                    return(new SolidWorksDelegateModel(Path.GetFileNameWithoutExtension(filePath), Description, Remark, aviablity, SWParam));
                }
                if (thisDocType == DocType.Enum)
                {
                    List <SolidWorksApiEnumMemberModel> SWEnumMembers = GetEnumMembers(doc);
                    return(new SolidWorksApiEnumModel(Path.GetFileNameWithoutExtension(filePath), Description, Remark, aviablity, SWEnumMembers));
                }
                if (thisDocType == DocType.Interface)
                {
                    return(new SolidWorksInterfaceModel(Path.GetFileNameWithoutExtension(filePath).Split('~')[1], Description, Remark, new List <SolidWorksApiMethodModel>(), new List <SolidWorksApiPropertyModel>()));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("   Error----" + ex.ToString());
            }
            return(null);
        }