mar*_*man 1 .net c# coding-style xml-documentation visual-studio
我一般在一个班级中宣称一个私人领域的土地以及一个从外面进入这个领域的公共财产(到目前为止没有什么壮观的笑容):
private bool doILookGood;
public bool DoILookGood
{
get { return doILookGood; }
set { doILookGood = value; }
}
Run Code Online (Sandbox Code Playgroud)
现在我想知道是否有一种优雅而有效的方式来评论这种情况,而无需两次写同样的评论.换句话说,我希望保留IDE在使用工具提示进行鼠标悬停时向我显示变量注释的功能.
到目前为止,我正在以这种方式发表评论:
/// <summary>
/// This i always true.
/// </summary>
private bool doILookGood;
/// <summary>
/// This i always true.
/// </summary>
public bool DoILookGood
{
get { return doILookGood; }
set { doILookGood = value; }
}
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
/// <summary>
/// This i always true.
/// </summary>
private bool doILookGood;
/// <summary cref="doILookGood" />
public bool DoILookGood
{
get { return doILookGood; }
set { doILookGood = value; }
}
Run Code Online (Sandbox Code Playgroud)
我知道使用XML标记来评论私有字段并不是很有意义,因为它们不会出现在生成的文档中,但我又只想拥有(IDE内部)评论工具提示.
也许有人有一个线索:)
尽可能使用自动属性.这将避免在不需要时使用私有成员.
public bool DoILookGood { get; set; }
Run Code Online (Sandbox Code Playgroud)
如果它不可能(例如在实现时INotifyPropertyChanged),这是我如何处理它(请注意它只是为了示例,我肯定会使用自动属性而不是下面的代码):
/// <summary>
/// Private member for <see cref="MyValue"/>.
/// </summary>
private bool myValue;
/// <summary>
/// Gets or sets a value indicating whether ...
/// </summary>
/// <value>
/// <c>true</c> if ...; otherwise, <c>false</c>.
/// </value>
public bool MyValue
{
get { return this.myValue; }
set { this.myValue = value; }
}
Run Code Online (Sandbox Code Playgroud)
编辑:我还建议使用GhostDoc来节省时间(一个能够自动生成注释的插件).
| 归档时间: |
|
| 查看次数: |
2122 次 |
| 最近记录: |