Home > Software design >  How to add documentation comments for a Dictionary/KeyValuePair in C#.NET
How to add documentation comments for a Dictionary/KeyValuePair in C#.NET

Time:12-11

Is there a proper way of describing a Dictionary type variable or a KeyValuePair with documentation comments in C#.

Something like this,

/// <summary>
/// User credentials
/// </summary>
/// <key>username</key>
/// <value>password</value>
private static Dictionary<string, string> credentials;

CodePudding user response:

Not sure what you really need here, but maybe like this?

/// <summary>
/// Dictionary of passwords by username
/// </summary>
Dictionary<string,string> Passwords

Good names are really your best doc, which you can supplement with the summary tags (or others as well).

Alternatively, you could make a custom class that inherits Dictionary and then provide a custom .Add(username,password) method and add comment tags to that. Or same thing, but Extend Dictionary instead.

CodePudding user response:

As already mentioned, there is no way to document such types in a structured way. I do this with a free text inside a <value> tag. This tag is primarily designed for properties but it's displayed in Intellisense also for fields.

My comment would look as follows:

/// <summary>
/// User credentials.
/// </summary>
/// <value>The collection of credentials where the key is a username and the value is a password.</value>
public static Dictionary<string, string> credentials;
  • Related