How to capture all the comments from class files (.cs) using C#?
User can maintain a log for all comments present in the class file. This will be used for maintainance purpose. Clean up activities can be done on basis of comments log.
User can add/delete required comments data. You can also put different filters. I hope it will be useful.
Concept description: User has to browse one class file (.cs) after clicking on button1. Code is used to read all file contents and find out whether comments are present in the file or not.
If comments are present in the file then it will capture it in Comments_logger.txt file which will be saved at D:\\Comments_logger.txt
Instead of hardcoded path for logger file, you can use web.config file and read the path by using configuration setting as well.
private void button1_Click(object sender, EventArgs e)
{
List
openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;
using (StreamReader sr = new StreamReader(textBox1.Text))
{
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.Trim().StartsWith("//"))
{
lst.Add(line + "\n");
}
}
}
using (StreamWriter outfile = new StreamWriter("D:\\" + "Comments_logger.txt"))
{
foreach (string str in lst)
{
outfile.Write(str + "\n");
}
}
}
What about Multiline comment...