Doxygen 并将属性值添加到输出文档

发布于 2025-01-05 17:48:05 字数 987 浏览 0 评论 0原文

ServiceStack 使用 C# 属性标记 Web 服务的静态路径。

例如,

[RestService("/hello1")]
[RestService("/hello2")]
public class Hello

我想让 Doxygen 在 Hello 类的 doxygen 输出中包含 RestService 属性的值。如果输出文档中包含带括号的整行,我不太关心漂亮的格式。

有什么建议吗?

一个快速而肮脏的技巧比编写 Doxygen 扩展更好;)

干杯

Tymek

====编辑

的 Python 版本(因此可以轻松地在 Windows 上工作)将是:

#!/usr/bin/env python
import sys
import re

if (len(sys.argv) < 2):
    print "No input file"
else:
    f = open(sys.argv[1])
    line = f.readline()
    while line:
        re1 = re.compile("\[RestService\(\"(.*)\",.*\"(.*)\"\)]")
        re1.search(line)
        sys.stdout.write(re1.sub(r"/** \\b RestService: \2 \1\\n */\n", line))
        #sys.stdout.write(line)
        line = f.readline()
    f.close()

doxygen 用户的答案 DOXYFILE 将具有:

INPUT_FILTER           = "doxygenFilter.py"

ServiceStack marks rest paths for web services using c# attributes.

For example

[RestService("/hello1")]
[RestService("/hello2")]
public class Hello

I would like to make Doxygen include values of the RestService attribute in the doxygen output for the Hello class. I'm not concerned too much with pretty formattin if the full line with brackets is included in the output document.

Any suggestions?

A quick and dirty trick would be a preferable to writing a Doxygen extension ;)

Cheers

Tymek

====EDIT

The Python version (so will work on Windows easily) of doxygen user's answer would be:

#!/usr/bin/env python
import sys
import re

if (len(sys.argv) < 2):
    print "No input file"
else:
    f = open(sys.argv[1])
    line = f.readline()
    while line:
        re1 = re.compile("\[RestService\(\"(.*)\",.*\"(.*)\"\)]")
        re1.search(line)
        sys.stdout.write(re1.sub(r"/** \\b RestService: \2 \1\\n */\n", line))
        #sys.stdout.write(line)
        line = f.readline()
    f.close()

and the DOXYFILE would have:

INPUT_FILTER           = "doxygenFilter.py"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您可以制作一个输入过滤器,将一行转换为

[RestService("/hello1")]

like

/** \b RestService: "/hello1"\n */

,例如,通过将以下 perl 魔法放入名为 filter.pl 的文件中:

open(F, "<", $ARGV[0]);
while(<F>) { /^\s*\[RestService\((.*)\)\]\s*$/ ? 
             print "/** \\b RestService: $1\\n */\n" : print $_; }

并将其与 INPUT_FILTER 一起使用Doxyfile 中的标签:

INPUT_FILTER           = "perl filter.pl"

You could make an input filter that converts a line with

[RestService("/hello1")]

to

/** \b RestService: "/hello1"\n */

like for instance by putting following piece of perl magic in a file called filter.pl:

open(F, "<", $ARGV[0]);
while(<F>) { /^\s*\[RestService\((.*)\)\]\s*$/ ? 
             print "/** \\b RestService: $1\\n */\n" : print $_; }

and use that with the INPUT_FILTER tag in the Doxyfile:

INPUT_FILTER           = "perl filter.pl"
手心的海 2025-01-12 17:48:05

对我来说,使用 C# 来代替 python 或 perl 脚本更有意义。

作为一个额外的好处,属性的内联 xml 文档也将添加到文档中。
示例:

[FromForm(Name = "e_mail")]
[Required] /// <div>Specifies that a data field value is required.</div><p>More info...</p>

将 C# 控制台项目命名为“AttributesDocumenter”,并将生成的二进制文件与 Doxyfile 中的 INPUT_FILTER 标记一起使用:
INPUT_FILTER = "AttributesDocumenter.exe"

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AttributesDocumenter
{
    class Program
    {
        static async Task Main(string[] args)
        {
            if (args.Length < 1)
            {
                await Console.Out.WriteLineAsync("No input file");
                return;
            }

            var f = File.OpenText(args[0]);
            while (!f.EndOfStream)
            {
                var line = await f.ReadLineAsync();
                var match = Regex.Match(line, @"\s*\[(.*)]\s*");

                if (match.Success)
                {
                    var inlineXmlComment = Regex.Match(line, @".*\/\/\/");
                    if (inlineXmlComment.Success)
                    {
                        var inlineXmlCommentList = new Regex(@"\s*(</?([^>/]*)/?>).*").Matches(line);
                        var inlineXmlCommentCombined = string.Join("", inlineXmlCommentList);
                        await Console.Out.WriteLineAsync($"{inlineXmlComment.Value} <para><b>Attribute:</b> {match.Value}</para> {inlineXmlCommentCombined}");
                    }
                    else
                    {
                        await Console.Out.WriteLineAsync($"{line} /// <para><b>Attribute:</b> {match.Value}</para>");
                    }
                }
                else
                {
                    await Console.Out.WriteLineAsync(line);
                }
            }
        }
    }
}

Instead of using a python or perl scrip, it made more sense to me to do it in C#

As an added bonus inline xml documentation for attributes will also be added to the documentation.
Example:

[FromForm(Name = "e_mail")]
[Required] /// <div>Specifies that a data field value is required.</div><p>More info...</p>

Name the C# console project "AttributesDocumenter" and use the resulting binary with the INPUT_FILTER tag in the Doxyfile:
INPUT_FILTER = "AttributesDocumenter.exe"

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AttributesDocumenter
{
    class Program
    {
        static async Task Main(string[] args)
        {
            if (args.Length < 1)
            {
                await Console.Out.WriteLineAsync("No input file");
                return;
            }

            var f = File.OpenText(args[0]);
            while (!f.EndOfStream)
            {
                var line = await f.ReadLineAsync();
                var match = Regex.Match(line, @"\s*\[(.*)]\s*");

                if (match.Success)
                {
                    var inlineXmlComment = Regex.Match(line, @".*\/\/\/");
                    if (inlineXmlComment.Success)
                    {
                        var inlineXmlCommentList = new Regex(@"\s*(</?([^>/]*)/?>).*").Matches(line);
                        var inlineXmlCommentCombined = string.Join("", inlineXmlCommentList);
                        await Console.Out.WriteLineAsync(
quot;{inlineXmlComment.Value} <para><b>Attribute:</b> {match.Value}</para> {inlineXmlCommentCombined}");
                    }
                    else
                    {
                        await Console.Out.WriteLineAsync(
quot;{line} /// <para><b>Attribute:</b> {match.Value}</para>");
                    }
                }
                else
                {
                    await Console.Out.WriteLineAsync(line);
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文