///// <summary> ///// 匹配有效注释(至少包含5个连续汉字) ///// </summary> //private static readonly Regex s_chineseRegex = new Regex(@"//.+[\u4e00-\u9fa5]{3,}", RegexOptions.Compiled); private void AnalyzeMethod(MethodCodeInfo method, out int lineCount, out int commentCount) { lineCount = 0; commentCount = 0; using (StringReader reader = new StringReader(method.Body)) { string line = null; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.Length < 5) // 忽略无效的代码,例如:花括号 { continue; } if (line == "continue;" || line == "break;" //|| line.EndsWith('=') // 赋值语句折行 //|| line.EndsWith("(") // 方法调用拆行 //|| line.EndsWith(',') // 赋值或者调用方法拆行 //|| line.StartsWith("&&") // 判断逻辑拆行 //|| line.EndsWith("&&") // 判断逻辑拆行 //|| line.StartsWith("||") // 判断逻辑拆行 //|| line.EndsWith("||") // 判断逻辑拆行 //|| line.StartsWith("?") // 判断逻辑拆行 //|| line.StartsWith(":") // 判断逻辑拆行 //|| (line.IndexOf(" = new ") > 0 && line.IndexOf(',') < 0) // 创建对象拆行 ) { continue; } //if( line.StartsWith("//") ) { // 注释行 // if( CommentRule.GetWordCount(line) >= 3 ) // commentCount++; //} //else { if (line.StartsWith("if") || line.StartsWith("for") || line.StartsWith("foreach") || line.StartsWith("while") || line.EndsWith(";") ) { lineCount++; } //} // 只要包含合理数量的汉字,就认为是一个有效的【注释行】, // 因为有时候就是处理汉字消息,再写汉字注释就显得多余了 if (CommentRule.GetWordCount(line) >= 3) { commentCount++; } } } }
public CommentRule DeserializeCommentRule(XElement commentRule) { return(CommentRule.FromXLinq(commentRule, this)); }