Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you provide xml comments/documentation for delegate parameters?

given a delegate like

Func<string,string,string> MyFunc = (firstName,lastName) => string.Format("Given Name:{0} Surname:{1}",
                                                                            firstName,
                                                                            lastName);

How would you can you document the parameters of firstName and lastName, so they show up in intellisense (like method descriptions and parameters do)?
Example:

/// <summary>
/// My Method
/// </summary>
/// <param name="firstName">The first name.</param>
/// <param name="lastName">The last name.</param>
/// <returns></returns> 
public string MyMethod(string firstName, string lastName)
{ 
  return string.Format("Given Name:{0} Surname:{1}",firstName,lastName);
}

I want to hover over the delegate or have intellisense popup when I type and tell me the descriptions for the the delegate parameters, like it would with the above method.

like image 590
Bless Yahu Avatar asked Feb 04 '23 06:02

Bless Yahu


1 Answers

A field of a delegate type is still a field and not a method—it doesn't take parameters in itself. The parameters belong to the delegate type, not the delegate field. You can write the comments for parameters when you delegate types if you want.

/// <summary>
/// Tests something.
/// </summary>
/// <param name="test">Something that's going to be tested.</param>
delegate void Test(int test);

Func<string,string,string> is a general delegate for functions with three parameters. For specific purposes, you can always declare your own delegate type that represents the abstracted method more specifically and add comments to its parameters.

like image 183
mmx Avatar answered Feb 05 '23 20:02

mmx