I am looking for a way to document action parameters in C#. Code looks like this:
/// <summary>
/// Do some action with parameters.
/// </summary>
/// <params name="someAction"> This is action but what about parameters? </param>
public void Do(Action<int,int,string> someAction)
How can I name and document parameters of "someAction" so that they would appear in intellisense?
You can use a nested structure.
/// <summary>
/// Does something useful.
/// </summary>
/// <param name="c">A constant</param>
/// <param name="someAction">
/// Here is an action.
/// <param name="someAction arg1">Count</param>
/// <param name="someAction arg2">Length</param>
/// <param name="someAction arg2">Content</param>
/// </param>
public void Do(int c, Action<int,int,string> someAction){}
It looks like this in the editor:
However, for complex structures, this is harder to maintain in the long run. If the context is not apparent intuitively, it is better and safer to create a class.
public class MyActionArgs : ActionArgs
{
public MyActionArgs(int count, int length, string content)
{
Count = count;
Length = length;
Content = content ?? throw new ArgumentNullException(nameof(content));
}
public int Count { get; }
public int Length { get; }
public string Content { get; }
}
public void Do(Action<MyActionArgs> myAction){}