locked
Reading Class, Method Summary using tool RRS feed

  • Question

  • User-1094550701 posted

    Is there any tool that we can use to fetch the documentation from a C# ".cs" file. For example we add 

    <summary> section before class and methods. and there are so many classes. and i want to make a word file that describes each file, its class summary and methods summary.

    Tho i  can copy from each file but if there is any tool to do this?

    Monday, May 6, 2013 10:40 AM

Answers

  • User281315223 posted

    It looks like this blog post discusses a very simple library that was written to allow you to access the summary information of specific methods and properties using Reflection as seen below : 

    //This grabs the specific documentation for a class / property
    XmlElement documentation = DocsByReflection.XMLFromMember(typeof(SomeExampleClass).GetProperty("ExampleProperty"));
    
    //This stores the specific documentation summary (what you are looking for) within a variable, which
    //could be sent as output to a file or however else you would like to handle it
    string summary = documentation["summary"].InnerText.Trim();

    It looks like the Jolt.NET project also handles this same exact functionality (although syntax may vary) and may be more recently maintained that the aforementioned blog post.

    (I haven't used either of these personally - but they should at least point you in the right direction.)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 6, 2013 10:45 AM
  • User-183374066 posted

    Following will log all the summary section for method

    StringBuilder str = new StringBuilder();
            
    using (StreamReader sr = new StreamReader("MyCSFilePath.cs"))
    {
        String line;
        while ((line = sr.ReadLine()) != null)
        {
            if (line.Trim().StartsWith("///"))
            {
                str.AppendLine(line);
            }
        }
    }
    using (StreamWriter outfile = new StreamWriter("D:\\" + "Summary.txt"))
    {
        outfile.Write(str.ToString() + "\n");
    }

    Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 6, 2013 10:50 AM

All replies

  • User281315223 posted

    It looks like this blog post discusses a very simple library that was written to allow you to access the summary information of specific methods and properties using Reflection as seen below : 

    //This grabs the specific documentation for a class / property
    XmlElement documentation = DocsByReflection.XMLFromMember(typeof(SomeExampleClass).GetProperty("ExampleProperty"));
    
    //This stores the specific documentation summary (what you are looking for) within a variable, which
    //could be sent as output to a file or however else you would like to handle it
    string summary = documentation["summary"].InnerText.Trim();

    It looks like the Jolt.NET project also handles this same exact functionality (although syntax may vary) and may be more recently maintained that the aforementioned blog post.

    (I haven't used either of these personally - but they should at least point you in the right direction.)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 6, 2013 10:45 AM
  • User-434868552 posted

    @ aithex2    welcome to forums.asp.net

    Sorry, you question is unclear.

    a c# file is a TEXT file so it has NO summary section, per se.

    Are you talking about the generic "Text file" with the .cs extension?

    it would be easier to answer your question if you were to expand it and clarify it ... perhaps you could started by explaining your goal(s).

    also, why to a Word file?

    g.

    P.S.:  if you're looking to document your code, check out applications like Sandcastle.  http://sandcastle.codeplex.com/

    Monday, May 6, 2013 10:48 AM
  • User-183374066 posted

    Following will log all the summary section for method

    StringBuilder str = new StringBuilder();
            
    using (StreamReader sr = new StreamReader("MyCSFilePath.cs"))
    {
        String line;
        while ((line = sr.ReadLine()) != null)
        {
            if (line.Trim().StartsWith("///"))
            {
                str.AppendLine(line);
            }
        }
    }
    using (StreamWriter outfile = new StreamWriter("D:\\" + "Summary.txt"))
    {
        outfile.Write(str.ToString() + "\n");
    }

    Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 6, 2013 10:50 AM
  • User455156504 posted

    Hi,

    there are a few tools out there, which can generate the documentation from the source files (f.e. from the summary comments). One is Sandcastle which isn't under development any more. Another one is Doxygen. The choice which tool to use is up to you.

    Monday, May 6, 2013 12:03 PM