ServiceStack使用c#属性标记Web服务的休息路径。
例如
[RestService("/hello1")]
[RestService("/hello2")]
public class Hello
我想在Hello类的doxygen输出中使Doxygen包含RestService属性的值。如果带有括号的完整行包含在输出文档中,我并不太关心漂亮的formattin。
有什么建议吗?
快速而肮脏的技巧比编写Doxygen扩展更好;)
干杯
Tymek
==== EDIT
doxygen 用户答案的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()
和DOXYFILE会有:
INPUT_FILTER = "doxygenFilter.py"
答案 0 :(得分:10)
您可以创建一个使用
转换行的输入过滤器[RestService("/hello1")]
到
/** \b RestService: "/hello1"\n */
例如,将以下perl魔法片段放在名为filter.pl
的文件中
open(F, "<", $ARGV[0]);
while(<F>) { /^\s*\[RestService\((.*)\)\]\s*$/ ?
print "/** \\b RestService: $1\\n */\n" : print $_; }
并将其与Doxyfile中的INPUT_FILTER
标记一起使用:
INPUT_FILTER = "perl filter.pl"
答案 1 :(得分:0)
使用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);
}
}
}
}
}