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.

How to capture all the comments from class files (.cs) using C#?
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 lst = new 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");
}
}

}


Comments

Author: Umesh Bhosale01 Apr 2014 Member Level: Silver   Points : 0

What about Multiline comment...



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: