コード例 #1
0
        private void getCodeSnippet(string FileToTest, int LineNumber, ref SourceCodeIssue issue)
        {
            string[] lines = File.ReadAllLines(FileToTest);
            int      start = 0;
            int      end   = lines.Length;

            if (LineNumber - Settings.Default.LinesBefore > 0)
            {
                start = LineNumber - Settings.Default.LinesBefore;
            }

            if (LineNumber + Settings.Default.LinesAfter < end)
            {
                end = LineNumber + Settings.Default.LinesAfter;
            }


            StringBuilder beforeSB = new StringBuilder();
            StringBuilder afterSB  = new StringBuilder();

            for (int i = start; i < LineNumber - 1; i++)
            {
                beforeSB.AppendLine(lines[i]);
            }
            for (int i = LineNumber; i < end; i++)
            {
                afterSB.AppendLine(lines[i]);
            }

            issue.CodeAfter  = afterSB.ToString();
            issue.CodeBefore = beforeSB.ToString();
        }
コード例 #2
0
        public List <SourceCodeIssue> FindIssues(string fileToTest)
        {
            List <SourceCodeIssue> issues = new List <SourceCodeIssue>();
            int currentLineNumber         = 1;

            foreach (string line in File.ReadAllLines(fileToTest))
            {
                if (_regex.IsMatch(line))
                {
                    SourceCodeIssue issue = new SourceCodeIssue();
                    issue.FilePath      = fileToTest;
                    issue.LineNumber    = currentLineNumber;
                    issue.RulePattern   = this;
                    issue.OffendingLine = line;
                    getCodeSnippet(fileToTest, currentLineNumber, ref issue);

                    issues.Add(issue);
                }
                currentLineNumber++;
            }
            return(issues);
        }
コード例 #3
0
ファイル: Rule.cs プロジェクト: nlsandler/YASAT
        private void getCodeSnippet(string FileToTest, int LineNumber, ref SourceCodeIssue issue)
        {
            string[] lines = File.ReadAllLines(FileToTest);
            int start = 0;
            int end = lines.Length;

            if (LineNumber - Settings.Default.LinesBefore > 0)
                start = LineNumber - Settings.Default.LinesBefore;

            if (LineNumber + Settings.Default.LinesAfter < end)
                end = LineNumber + Settings.Default.LinesAfter;

            StringBuilder beforeSB = new StringBuilder();
            StringBuilder afterSB = new StringBuilder();
            for (int i = start; i < LineNumber-1; i++)
                beforeSB.AppendLine(lines[i]);
            for (int i = LineNumber; i < end; i++)
                afterSB.AppendLine(lines[i]);

            issue.CodeAfter = afterSB.ToString();
            issue.CodeBefore = beforeSB.ToString();
        }
コード例 #4
0
ファイル: Rule.cs プロジェクト: nlsandler/YASAT
        public List<SourceCodeIssue> FindIssues(string fileToTest)
        {
            List<SourceCodeIssue> issues = new List<SourceCodeIssue>();
            int currentLineNumber = 1;

            foreach (string line in File.ReadAllLines(fileToTest))
            {
                if (_regex.IsMatch(line))
                {
                    SourceCodeIssue issue = new SourceCodeIssue();
                    issue.FilePath = fileToTest;
                    issue.LineNumber = currentLineNumber;
                    issue.RulePattern = this;
                    issue.OffendingLine = line;
                    getCodeSnippet(fileToTest, currentLineNumber, ref issue);

                    issues.Add(issue);
                }
                currentLineNumber++;
            }
            return issues;
        }