我正在使用 Doxygen 1.8.9.1 为我的 C# 代码生成一些 html 文档。问题是 Doxygen 似乎不理解对同一类中方法的方法调用,除非您在方法名称之前明确键入类名称。
在这个示例类中,我有 2 个相同的静态方法和 1 个同时调用它们的方法;一种只包含方法名称,另一种包含类名。当我生成文档时,只有 someStaticMethod2
链接到 somecaller
。 someStaticMethod
没有链接到任何东西。
public class Class1 {
static void someStaticMethod() {
}
static void someStaticMethod2() {
}
void somecaller() {
someStaticMethod();
Class1.someStaticMethod2();
}
}
在我的 Doxygen 配置中,我勾选了我能看到的每个“提取”选项,即
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = YES
EXTRACT_ANON_NSPACES = YES
我看过相关问题,但他们没有答案..
有什么想法吗?
谢谢
汤姆
最佳答案
作为一种快速解决方法,我使用 python 制作了这个 Doxygen 输入过滤器。它假定您有一个 .cs
源文件,其中包含一个包含静态方法的主类。它有点困惑,因为它没有进行正确的语法解析,但它对我有用;)
它采用 .cs
输入文件,获取类名并将其添加到类中找到的任何静态函数调用之前,以将 someStaticMethod
之类的调用替换为 Class1.someStaticMethod
要使用,只需将此添加到 Doxygen 配置中:
FILTER_PATTERNS = *.cs=DocPreprocess.bat
bat 文件只是 python 脚本的包装器,如下所示:
@echo off
cd %~dp0
C:\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\python.exe DocPreprocess.py %1
只需确保 bat 文件在路径上或 Doxygen 启动文件夹中即可。
文档预处理.py
import re
import sys
original = open(sys.argv[1],"rb").read();
#remove quoted sections and char literal braces
regex = re.compile('"([^"]*)"', re.IGNORECASE)
buffer = regex.sub("", original).replace("'{'","").replace("'}'","")
#remove comments
newbuffer = ""
for l in buffer.splitlines():
code,_,comment = l.partition(r"//")
newbuffer += code
buffer = " ".join(newbuffer.split())
#get static functions and main class name
depth = 0
classname = ""
classdepth = 0
funcs = []
while True:
nopen = buffer.find("{")
nclose = buffer.find("}")
if nclose==-1 and nopen>-1: nclose=nopen+1
if nclose>-1 and nopen==-1: nopen=nclose+1
if nclose==-1 and nopen==-1: break
if nopen < nclose:
chunk,_,buffer = buffer.partition("{")
depth+=1
else:
chunk,_,buffer = buffer.partition("}")
depth-=1
chunk = chunk.strip()
if "public class" in chunk and classname == "":
classname = chunk.split()[-1]
classdepth = depth
if classdepth and depth > classdepth and "static" in chunk and chunk.endswith(")"):
funcs.append(chunk.rpartition("(")[0].split()[-1])
#replace
fixed = ""
for l in original.splitlines():
words = l.split()
stripped = l.strip()
if "static" in words[0:3] or stripped.startswith("//") or stripped.startswith("#"):
#ignore function defs and comments
fixed += l + "\n"
continue
for f in funcs:
newname = classname+"."+f
l=l.replace(newname,"[[TEMPTOKEN]]")
l=l.replace(f,newname)
l=l.replace("[[TEMPTOKEN]]",newname)
fixed += l + "\n"
#output fixed file to stdout
print fixed
这只是获得我想要的东西的 hack,我仍然真的很想看到一个真正的解决方案来让 Doxygen 自动执行此操作。
谢谢
汤姆
关于c# - Doxygen 不会生成指向没有显式类名的方法的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111803/