Is it possible to have one comment for property and private variable
Hello everyone, my question is very simple.
/// <summary>
/// a description here. for internal use
/// </summary>
private A _Owner;
/// <summary>
/// Same description also here. for outside use
/// </summary>
public A Owner
{
get { return _Owner; }
set { _Owner = value; }
}
Is there a way to avoid writing the same comment twice? It's just a nuisance.
source to share
First, note that you don't need intellisense comments for private members, including fields. Therefore, you can simply delete the first comment. If the value of the field is not obvious from the name, you have not named it appropriately.
Second, for most simple properties, you can remove the explicit field declaration entirely ...
/// <summary>a description here</summary>
public A Owner {get;set;}
source to share
Use Auto-Implemented Properties and then you can specify one XML comment for that property.
/// <summary>
/// Same description also here. for outside use
/// </summary>
public A Owner
{
get; set;
}
But if you are doing something with a private field in your get or set, you need to include the XML comments twice.
One more thing, you probably only need to specify XML comments for the property , since this is public outside of the class and not for your public field.
source to share
No, there is no way to avoid this as intelisense links wrote a comment on the found code artifact. In your case, you have 2 of them:
- one is
property
. - the other is
field
.
So in your case you will need to write it twice, or as the generated ones suggested, use the auto property and define it once.
source to share