自动提取C#类文件中的代码注释文字
来源:互联网 发布:杭州淘宝运营 编辑:程序博客网 时间:2024/06/05 14:57
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Runtime.Remoting" %>
<%@ Import Namespace="System.Runtime.Remoting.Lifetime" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
string Folder = "C_BLL";//需要获取的文件夹
string pContent;
string KeywordFormat(string inputString)
{
string ks = "public,private,static,class,virtual,override,new,void,string,int,bool,double,float,char,byte,DateTime,set,get";
string[] ka = ks.Split(',');
string outputString = inputString;
foreach (string kg in ka)
{
outputString = outputString.Replace(kg + " ", "<font class=/"keyword/">" + kg + " </font>");
outputString = outputString.Replace("(" + kg + ")", "(<font class=/"keyword/">" + kg + "</font>)");
outputString = outputString.Replace(kg + "[", "<font class=/"keyword/">" + kg + "</font>[");
}
return outputString;
}
protected void Page_Load(object sender, EventArgs e)
{
pContent = "";
// 用于保存结果
StringBuilder sb = new StringBuilder();
// 用于保存注释
StringBuilder sm = new StringBuilder();
// 遍历指定目录下的全部 CS 文件
DirectoryInfo csfile = new DirectoryInfo(Server.MapPath(Folder));
foreach (System.IO.FileInfo fi in csfile.GetFiles())
{
int depth = 0;
sb.AppendLine("<div style=/"padding:4px;margin:10px;padding-left:20px;border:solid 1px #AAAAAA;background-color:#F0F0F0/">");
sb.AppendLine("<font class=/"file/"><b>" + Folder + "/" + fi.Name.ToString() + "</font> ");
StreamReader TxtReader = new StreamReader(Server.MapPath(Folder + "/" + fi.Name.ToString()), System.Text.Encoding.Default);
string FileContent = TxtReader.ReadToEnd();
TxtReader.Close();
// 按行分割
string[] fLines = Regex.Split(FileContent, "/r/n");
// 未进入注释段
int ok = 0;
foreach (string ls in fLines)
{
string vls = ls;
// 如果是 namespace
if (vls.Length > 10)
{
if (vls.Substring(0, 9) == "namespace")
{
sb.AppendLine(" ~~~ <font class=/"namespace/">" + vls.Substring(10) + "</font></b></div>");
depth = 1;
//sb.AppendLine("<div style=/"padding:4px;margin:10px;padding-left:" + (depth*40+20) + "px/">");
continue;
}
}
vls = vls.Trim();
if (vls.Length >= 3)
{
if (vls.Substring(0, 3) == "///")
{
//sb.AppendLine("<font class=/"summary/">");
// 如果是说明行,跳过即可
if (vls.Contains("<summary>"))
{
// 已进入注释段
ok = 1;
sm.Append("功能:");
continue;
}
if (vls.Contains("</summary>"))
{
// 已进入注释段
ok = 1;
continue;
}
string gls = vls.Replace("///", "").Trim();
if (gls.Length > 2)
{
vls = vls.Replace("<param name=/"", "参数:");
vls = vls.Replace("/">", " ");
vls = vls.Replace("</param>", "");
vls = vls.Replace("<returns></returns>", "");
vls = vls.Replace("<returns>", "返回:");
vls = vls.Replace("</returns>", "");
vls = vls.Replace("///", "").Trim();
if (vls != "")
{
sm.AppendLine(vls.Trim() + "<br>");
}
}
// 已进入注释段
ok = 1;
}
else
{
// 如果已经进入注释段
if (ok == 1)
{
// 如果是类
if (ls.Contains(" class "))
{
sb.AppendLine("<div style=/"padding:4px;margin:4px;padding-left:60px/">");
sb.AppendLine("<font class=/"summary/">" + sm.ToString() + "</font>");
sb.AppendLine("<font class=/"class/">" + KeywordFormat(ls.Trim()) + "</font>");
sb.AppendLine("</div>");
}
else
{
sb.AppendLine("<div style=/"padding:4px;margin:4px;padding-left:100px/">");
sb.AppendLine("<font class=/"summary/">" + sm.ToString() + "</font>");
string kls = ls.Trim();
if (kls.Substring(kls.Length - 1, 1) == ")")
sb.AppendLine("<font class=/"function/">方法:" + KeywordFormat(kls) + "</font>");
else
sb.AppendLine("<font class=/"property/">属性:" + KeywordFormat(kls) + "</font>");
sb.AppendLine("</div>");
}
ok = 0;
sm.Remove(0, sm.Length);
}
}
}
}
if (depth > 0) sb.AppendLine("</div>");
if (depth > 1) sb.AppendLine("</div>");
sb.AppendLine("</div>");
}
pContent = sb.ToString();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>C#类地图</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.keyword { font-size:12px;color:#0000EE;font-weight:normal; }
.file { font-size:16px;color:#000000; }
.namespace { font-size:16px;color:#990000; }
.class { font-size:14px;color:#AA0000;font-weight:bold; }
.function { font-size:12px;color:#333333;font-weight:bold; }
.property { font-size:12px;color:#888800;font-weight:bold; }
.summary { font-size:12px;color:#888888; }
-->
</style>
</head>
<body style="font-size:12px;font-family:arial,宋体;line-height:16px;">
<% =pContent %>
</body>
</html>
- 自动提取C#类文件中的代码注释文字
- C#提取HTML代码中的文字zt
- C#提取HTML代码中的文字
- C#提取HTML代码中的文字
- C#提取HTML代码中的文字
- 在C#代码中提取PDF中的注释文本
- 提取chm文件中的文字和图片
- 在C#类文件 自动添加文件注释的方法
- c语言自动删除cpp文件中的注释 使用代码删除注释【Linux、mac下】
- C#为类文件自动添加头注释
- antlr提取代码注释
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- [转]提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 测试报告编写指南
- 灰色的2009年年底
- AX中的收藏夹备份
- nagios监控mysql主从复制
- 使用ADF文本编辑器(RichTextEditor)组件
- 自动提取C#类文件中的代码注释文字
- VOA背景音乐
- some note about js
- 关于软件开发的 语法学习 和 框架之类 的应用的考虑
- 自动化测试框架开发5步法
- JavaScript去掉字符串的前后空格
- sqm文件
- 选择Icon文件来替换EXE的图标
- 火狐不执行js的一些解决办法及火狐对js的兼容问题