假设我有这个界面
public interface IFoo
{
///<summary>
/// Foo method
///</summary>
void Foo();
///<summary>
/// Bar method
///</summary>
void Bar();
///<summary>
/// Situation normal
///</summary>
void Snafu();
}
还有这个类
public class Foo : IFoo
{
public void Foo() { ... }
public void Bar() { ... }
public void Snafu() { ... }
}
有没有办法,或者有什么工具可以让我自动把每个成员的注释放到基类或接口(interface)中?
因为我讨厌为每个派生子类重写相同的注释!
最佳答案
您始终可以使用 <inheritdoc />
标签:
public class Foo : IFoo
{
/// <inheritdoc />
public void Foo() { ... }
/// <inheritdoc />
public void Bar() { ... }
/// <inheritdoc />
public void Snafu() { ... }
}
使用 cref
属性,您甚至可以在完全不同的类或命名空间中引用完全不同的成员!
public class Foo
{
/// <inheritdoc cref="System.String.IndexOf" />
public void Bar() { ... } // this method will now have the documentation of System.String.IndexOf
}
关于c# - 从实现类中的接口(interface)继承注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27540290/