jum*_*kie 84 c# inheritance comments
假设我有这个界面
public interface IFoo
{
///<summary>
/// Foo method
///</summary>
void Foo();
///<summary>
/// Bar method
///</summary>
void Bar();
///<summary>
/// Situation normal
///</summary>
void Snafu();
}
Run Code Online (Sandbox Code Playgroud)
而这堂课
public class Foo : IFoo
{
public void Foo() { ... }
public void Bar() { ... }
public void Snafu() { ... }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法,还是有一个工具可以让我自动放入基类或接口中每个成员的注释?
因为我讨厌为每个派生的子类重写相同的注释!
Vad*_*dim 139
你总是可以使用<inheritdoc />
标签.
public class Foo : IFoo
{
/// <inheritdoc />
public void Foo() { ... }
/// <inheritdoc />
public void Bar() { ... }
/// <inheritdoc />
public void Snafu() { ... }
}
Run Code Online (Sandbox Code Playgroud)
Den*_*nis 19
/// <inheritdoc/>
如果要继承,请使用.避免GhostDoc或类似的东西.
我同意,评论不是继承的,这很烦人.如果有人有时间(我希望我这样做),这将是一个相当简单的插件.
也就是说,在我们的代码库中,我们只在接口上放置XML注释,并为类添加额外的实现注释.这适用于我们,因为我们的类是私有/内部的,只有接口是公共的.每当我们通过接口使用对象时,我们都会在intellisence中显示完整的注释.
GhostDoc是一个良好的开端,并使该过程更容易编写注释.添加/删除参数,重新运行GhostDoc并更新描述时,使注释保持最新非常有用.
Jam*_*ran 16
GhostDoc正是如此.对于未继承的方法,它尝试从名称中创建描述.
FlingThing()
变 "Flings the Thing"
Jef*_*ton 14
Java有这个,我一直都在使用它.做就是了:
/**
* {@inheritDoc}
*/
Run Code Online (Sandbox Code Playgroud)
Javadoc工具可以解决这个问题.
C#有类似的标记:
<inheritDoc/>
Run Code Online (Sandbox Code Playgroud)
你可以在这里阅读更多:
http://www.ewoodruff.us/shfbdocs/html/79897974-ffc9-4b84-91a5-e50c66a0221d.htm
我会说要直接使用
/// <inheritdoc cref="YourClass.YourMethod"/> --> For methods inheritance
Run Code Online (Sandbox Code Playgroud)
和
/// <inheritdoc cref="YourClass"/> --> For directly class inheritance
Run Code Online (Sandbox Code Playgroud)
您必须将此注释放在类/方法的上一行
这将从您已记录的界面获取您的注释信息,例如:
/// <summary>
/// This method is awesome!
/// </summary>
/// <param name="awesomeParam">The awesome parameter of the month!.</param>
/// <returns>A <see cref="AwesomeObject"/> that is also awesome...</returns>
AwesomeObject CreateAwesome(WhateverObject awesomeParam);
Run Code Online (Sandbox Code Playgroud)
小智 5
另一种方法是使用<see />
XML文档标签。这是一些额外的工作,但可以立即使用...
这里有些例子:
/// <summary>
/// Implementation of <see cref="IFoo"/>.
/// </summary>
public class Foo : IFoo
{
/// <summary>
/// See <see cref="IFoo"/>.
/// </summary>
public void Foo() { ... }
/// <summary>
/// See <see cref="IFoo.Bar"/>
/// </summary>
public void Bar() { ... }
/// <summary>
/// This implementation of <see cref="IFoo.Snafu"/> uses the a caching algorithm for performance optimization.
/// </summary>
public void Snafu() { ... }
}
Run Code Online (Sandbox Code Playgroud)
更新:
我现在更喜欢使用/// <inheritdoc/>
ReSharper支持的功能。
归档时间: |
|
查看次数: |
63282 次 |
最近记录: |