I would like to add portions of the source code to the XML documentation. I could copy and paste the source code into some <code> elements, for example:
/// <summary> /// Says hello world in a very basic way: /// <code> /// System.Console.WriteLine("Hello World!"); /// System.Console.WriteLine("Press any key to exit."); /// System.Console.ReadKey(); /// </code> /// </summary> static void Main() { System.Console.WriteLine("Hello World!"); System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }
Maintaining this will be painful. Are there other ways to add source code to XML documentation in C #?
I am processing XML documentation using Sandcastle and want to make a technical help file (* .chm) out of it. I would like to add parts or full bodies of methods to the help file.
EDIT: Thanks for the comment from slide_rule. I added a more realistic and less trivial example:
Suppose I have a method like this:
public decimal CalculateFee(Bill bill) { if (bill.TotalSum < 5000) return 500; else { if (bill.ContainsSpecialOffer) return bill.TotalSum * 0.01; else return bill.TotalSum * 0.02; } }
It would be nice to add information on how the board is calculated in the technical assistance file.
The most obvious solution would be to write the algorithm as a prosaic text in a comment like: "If the account has a total of less than 5000, then ...".
Another solution would be to copy and paste the body of the method into the comment field and put it in the <code> element. This body method can be understood quite easily, even without much knowledge of C #, so there is nothing wrong with putting it in a technical help file.
Both solutions violate the DRY principle! I would like to add the method body or part of the method body to the help file without duplicating the information.
Is this possible in C #? (I think that RDoc for Ruby is able to do this, but I need some solution in C #)
Theo lendndff
source share