In c# with functions you can add document comments like this:
///<summary>
///
///</summary>
///<param name=""></param>
///<returns></returns>
When using a normal function, this autogenerates. However, when using lambdas nothing happens. Is there a way to use document comments with lambdas?
Many lambda expressions do not require you to write documentation, because it already exists.
For example, if you supply a lambda expression to a Where clause, function is already documented here (although it doesn't have a ton of detail):
predicate
Type: System.Func
A function to test each element for a condition.
I would suggest if you have an extension method or other sort of code that takes a lambda expression as an argument, the appropriate place to document its inputs and outputs is with the method that uses it, not the code that sets it.
On the other hand, if you need to document the internal workings of your particular implementation of the lambda (i.e. it is very complicated) I would suggest you implement it as a standard c# method that matches the signature.
Thus instead of
Users
.Where( r => {
DoSomethingComplicated();
MoreCode();
return FinalResult();
});
You'd simply write
Users.Where( MyFunction )
Then define the function elsewhere:
/// <summary>
/// This function calls DoSomethingComplicated and MoreCode
/// </summary>
/// <returns> A Boolean specifying whether the user should be included </returns>
bool MyFunction(User user)
{
DoSomethingComplicated();
MoreCode();
return FinalResult();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With