Example #1
0
        /// <summary>
        /// Генерирует Wiki-описание метода.
        /// </summary>
        /// <param name="method">Метод, для которого необходимо получить описание.</param>
        /// <returns>
        /// Wiki-описание метода.
        /// </returns>
        public static string GenerateWikiMethod(VkDocMethod method)
        {
            if (method == null)
            {
                return(string.Empty);
            }

            var template = new StringBuilder(ReadFile(@"templates\method.txt"));

            if (string.IsNullOrEmpty(template.ToString()))
            {
                throw new IOException("Method template not found.");
            }

            template.Replace(Placeholder.MethodName, method.ShortName);
            template.Replace(Placeholder.CategoryName, method.Type.ShortName.Replace("Category", string.Empty));
            template.Replace(Placeholder.MethodDesc, method.Summary);
            template.Replace(Placeholder.MethodResult, method.Returns);
            template.Replace(Placeholder.MethodRamarks, method.Remarks);
            template.Replace(Placeholder.MethodSignature, method.Signature);
            template.Replace(Placeholder.Namespace, method.Namespace);
            template.Replace(Placeholder.ReturnType, method.ReturnType);

            var parameters = new StringBuilder();

            if (method.Params.Count == 0)
            {
                parameters.Append("Данный метод не принимает параметров.");
            }
            else
            {
                parameters.Append("|| Параметр || Описание ||").AppendLine();
                foreach (var p in method.Params)
                {
                    parameters.AppendFormat("| {0} | {1} |{2}", p.Name, p.Description, Environment.NewLine);
                }
            }

            template.Replace(Placeholder.ParamsList, parameters.ToString());

            if (method.Examples.Count > 0)
            {
                template.AppendLine().AppendLine("!! Пример").AppendLine("----");
            }

            foreach (var example in method.Examples)
            {
                var wikiExample = TrimLines(example).Replace("<code>", "{code:c#}").Replace("</code>", "{code:c#}");
                template
                .Append("* ")
                .AppendLine(wikiExample);
            }

            return(template.ToString());
        }
Example #2
0
        public void Signature_OneItem()
        {
            var param = new VkDocMethodParam
                {
                    Name = "uid",
                    Description = "Идентификатор пользователя"
                };

            var method = new VkDocMethod { FullName = "VkNet.Categories.AudioCategory.GetFromGroup(System.Int64)" };
            method.Params.Add(param);

            method.Signature.ShouldEqual("GetFromGroup(long uid)");
        }
Example #3
0
        public void Signature_CustomType()
        {
            var first = new VkDocMethodParam {Name = "isEnabled"};
            var second = new VkDocMethodParam {Name = "filter"};
            var third = new VkDocMethodParam {Name = "fields"};

            var method = new VkDocMethod { FullName = "VkNet.Categories.GroupsCategory.Get(System.Boolean,VkNet.Enums.GroupsFilters,VkNet.Enums.GroupsFields)" };
            method.Params.Add(first);
            method.Params.Add(second);
            method.Params.Add(third);

            method.Signature.ShouldEqual("Get(bool isEnabled, GroupsFilters filter, GroupsFields fields)");
        }
Example #4
0
        public void Signature_TwoNullableParams()
        {
            var first = new VkDocMethodParam{Name = "uid"};
            var second = new VkDocMethodParam {Name = "count"};

            var method = new VkDocMethod
                {
                    FullName =
                        "VkNet.Categories.VideoCategory.Get(System.Nullable{System.Int64},System.Nullable{System.Int64})"
                };
            method.Params.Add(first);
            method.Params.Add(second);

            method.Signature.ShouldEqual("Get(long? uid = null, long? count = null)");
        }
Example #5
0
        private VkDocMethod GetVkDocMethod(XmlReader xml)
        {
            var method = new VkDocMethod {
                FullName = GetMemberName(xml, "M:")
            };

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "member")
                {
                    break;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "summary")
                {
                    //method.Summary = xml.ReadElementContentAsString().Trim();
                    method.Summary = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "remarks")
                {
                    method.Remarks = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "returns")
                {
                    method.Returns = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "param")
                {
                    method.Params.Add(GetParam(xml));
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "example")
                {
                    method.Examples.Add(xml.ReadInnerXml().Trim());
                }
            }

            return(method);
        }
Example #6
0
        /// <summary>
        /// Генерирует Wiki-описание метода.
        /// </summary>
        /// <param name="method">Метод, для которого необходимо получить описание.</param>
        /// <returns>
        /// Wiki-описание метода.
        /// </returns>
        public static string GenerateWikiMethod(VkDocMethod method)
        {
            if (method == null) return string.Empty;

            var template = new StringBuilder(ReadFile(@"templates\method.txt"));

            if (string.IsNullOrEmpty(template.ToString())) 
                throw new IOException("Method template not found.");

            template.Replace(Placeholder.MethodName, method.ShortName);
            template.Replace(Placeholder.CategoryName, method.Type.ShortName.Replace("Category", string.Empty));
            template.Replace(Placeholder.MethodDesc, method.Summary);
            template.Replace(Placeholder.MethodResult, method.Returns);
            template.Replace(Placeholder.MethodRamarks, method.Remarks);
            template.Replace(Placeholder.MethodSignature, method.Signature);
            template.Replace(Placeholder.Namespace, method.Namespace);
            template.Replace(Placeholder.ReturnType, method.ReturnType);

            var parameters = new StringBuilder();
            if (method.Params.Count == 0)
            {
                parameters.Append("Данный метод не принимает параметров.");
            }
            else
            {
                parameters.Append("|| Параметр || Описание ||").AppendLine();
                foreach (var p in method.Params)
                    parameters.AppendFormat("| {0} | {1} |{2}", p.Name, p.Description, Environment.NewLine);
            }

            template.Replace(Placeholder.ParamsList, parameters.ToString());

            if (method.Examples.Count > 0)
                template.AppendLine().AppendLine("!! Пример").AppendLine("----");

            foreach (var example in method.Examples)
            {
                var wikiExample = TrimLines(example).Replace("<code>", "{code:c#}").Replace("</code>", "{code:c#}");
                template
                    .Append("* ")
                    .AppendLine(wikiExample);
            }
            
            return template.ToString();
        }
Example #7
0
        private VkDocMethod GetVkDocMethod(XmlReader xml)
        {
            var method = new VkDocMethod {FullName = GetMemberName(xml, "M:")};

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.EndElement && xml.Name == "member")
                    break;

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "summary")
                {
                    //method.Summary = xml.ReadElementContentAsString().Trim();
                    method.Summary = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "remarks")
                {
                    method.Remarks = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "returns")
                {
                    method.Returns = xml.ReadInnerXml().Trim();
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "param")
                {
                    method.Params.Add(GetParam(xml));
                    continue;
                }

                if (xml.NodeType == XmlNodeType.Element && xml.Name == "example")
                    method.Examples.Add(xml.ReadInnerXml().Trim());
            }

            return method;
        }
Example #8
0
        public void Signature_WithoutParams()
        {
            var method = new VkDocMethod { FullName = "M:VkNet.Categories.UtilsCategory.GetServerTime" };

            method.Signature.ShouldEqual("GetServerTime()");
        }