Exemplo n.º 1
0
        private static void AddObsoleteAttribute(Declaration function)
        {
            var obsoleteMessageBuilder = new StringBuilder();

            obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(HtmlEncoder.HtmlEncode(function.Comment.BriefText).Split(
                                                                     Environment.NewLine.ToCharArray()).FirstOrDefault(line => line.Contains("instead") || line.Contains("deprecated"))));
            function.Attributes.Add(new Attribute
            {
                Type  = typeof(ObsoleteAttribute),
                Value = $"\"{obsoleteMessageBuilder}\""
            });
        }
Exemplo n.º 2
0
        private static void AddObsoleteAttribute(Declaration function)
        {
            StringBuilder obsoleteMessageBuilder = new StringBuilder();

            obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(HtmlEncoder.HtmlEncode(function.Comment.BriefText).Split(
                                                                     Environment.NewLine.ToCharArray()).FirstOrDefault(line => line.Contains("instead") || line.Contains("deprecated"))));
            Attribute annotation = new Attribute();

            annotation.Type  = typeof(ObsoleteAttribute);
            annotation.Value = string.Format("\"{0}\"", obsoleteMessageBuilder);
            function.Attributes.Add(annotation);
        }
Exemplo n.º 3
0
    public static void FormatComment(string docs, CodeTypeMember cmp, bool obsolete = false, string tag = "summary")
    {
        StringBuilder obsoleteMessageBuilder = new StringBuilder();

        cmp.Comments.Add(new CodeCommentStatement(string.Format("<{0}>", tag), true));
        foreach (string line in HtmlEncoder.HtmlEncode(docs).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.None))
        {
            cmp.Comments.Add(new CodeCommentStatement(string.Format("<para>{0}</para>", line), true));
            if (obsolete && (line.Contains("instead") || line.Contains("deprecated")))
            {
                obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(line));
                obsoleteMessageBuilder.Append(' ');
            }
        }
        cmp.Comments.Add(new CodeCommentStatement(string.Format("</{0}>", tag), true));
        if (obsoleteMessageBuilder.Length > 0)
        {
            obsoleteMessageBuilder.Remove(obsoleteMessageBuilder.Length - 1, 1);
            CodeTypeReference       obsoleteAttribute = new CodeTypeReference(typeof(ObsoleteAttribute));
            CodePrimitiveExpression obsoleteMessage   = new CodePrimitiveExpression(obsoleteMessageBuilder.ToString());
            cmp.CustomAttributes.Add(new CodeAttributeDeclaration(obsoleteAttribute, new CodeAttributeArgument(obsoleteMessage)));
        }
    }
Exemplo n.º 4
0
    private static string StripTags(string source)
    {
        char[]      array      = new char[source.Length];
        List <char> tagArray   = new List <char>();
        int         arrayIndex = 0;
        bool        inside     = false;

        foreach (char @let in source)
        {
            if (@let == '<')
            {
                inside = true;
                continue;
            }
            if (@let == '>')
            {
                inside = false;
                continue;
            }
            if (inside)
            {
                tagArray.Add(@let);
            }
            else
            {
                string tag = new string(tagArray.ToArray());
                if (tag.Contains("/tdtd"))
                {
                    array[arrayIndex++] = '\t';
                }
                tagArray.Clear();
                array[arrayIndex++] = @let;
            }
        }
        return(HtmlEncoder.HtmlDecode(new string(array, 0, arrayIndex)));
    }
Exemplo n.º 5
0
        private static string StripTags(string source, bool trim = false)
        {
            var array          = new List <char>(source.Length);
            var tagArray       = new List <char>();
            var inside         = false;
            var literalBuilder = new StringBuilder();

            foreach (var character in source)
            {
                if (character == '<')
                {
                    inside = true;
                    continue;
                }
                if (character == '>')
                {
                    if (tagArray.Count < 5 || tagArray[0] != '!' || tagArray[1] != '-' || tagArray[2] != '-' ||
                        (tagArray[tagArray.Count - 2] == '-' && tagArray[tagArray.Count - 1] == '-'))
                    {
                        inside = false;
                    }
                    continue;
                }
                if (inside)
                {
                    tagArray.Add(character);
                }
                else
                {
                    string tag = new string(tagArray.ToArray());
                    if (tag.Contains("/tdtd"))
                    {
                        array.Add('\t');
                    }
                    tagArray.Clear();
                    switch (character)
                    {
                    case '&':
                        literalBuilder.Append(character);
                        break;

                    case ';':
                        literalBuilder.Append(character);
                        var literal = literalBuilder.ToString();
                        if (!string.IsNullOrEmpty(literal) && literal != "&#8203;")
                        {
                            array.AddRange(literal);
                        }
                        literalBuilder.Clear();
                        break;

                    default:
                        if (literalBuilder.Length > 0)
                        {
                            literalBuilder.Append(character);
                        }
                        else
                        {
                            array.Add(character);
                        }
                        break;
                    }
                }
            }
            var decoded = HtmlEncoder.HtmlDecode(new string(array.ToArray(), 0, array.Count));

            return(trim ? decoded.Trim() : decoded);
        }