C#中用正则表达式检测.cs文件头文件注释格式是否正确

来源:百度知道 编辑:UC知道 时间:2024/06/17 18:45:47
语言用c#,写一段代码,实现用正则表达式检查.cs文件(任意一个不相关的cs文件都可以)中头文件的注释是否符合规范。
例如(头文件为多行的注释):
/*
author:#######
date: #######
overview:#######
*/

###代表任意内容。 简单来说是读取一个.cs文件,要检查注释是否存在,格式要包括作者、日期、还有概述,但是其内容不管,只用正则表达式检查注释格式是否正确。然后输出结果。 求高手解答,有完整代码最好,最关键的是正则表达式。谢谢!
谢谢各位的解答,对于FantasyChump的代码,请问 foreach里面的WL(line)是如何定义的!??

System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^\s*/\*((\s)*(?<line>.+)\s*)+\*/");
bool isDateValid, isAuthorValid, isOverviewValid;
isDateValid = isAuthorValid = isOverviewValid = false;
System.Text.RegularExpressions.Match m=reg.Match("/*\r\nauthor:#######\r\ndate: ####### \r\noverview:####### \r\n*********/ ");

bool isCommentValid = false;

if (m.Success)
{
foreach (System.Text.RegularExpressions.Capture cap in m.Groups["line"].Captures)
{
string line = cap.Value.Trim().ToLower();
if (line.StartsWith("date:")) isDateValid = true;
if (line.StartsWith("overview:")) isOverviewValid = true;
if (line.StartsWith("author:")) isAuthorValid = true;
WL(line);
}

isCommentValid = isDateV