c# - 从实现类中的接口(interface)继承注释?

标签 c# inheritance comments

假设我有这个界面

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/

相关文章:

c# - 为什么 cmd.executeNonQuery() 抛出 ManagedDataAccess.Client.OracleException?

c# - ExecuteNonQuery 返回 1,即使更新语句没有影响任何行

ruby-on-rails - 无法将 current_user.name 作为注释的属性传递

c# - 用 001 和 1 初始化 int 有区别吗?

c# - 如何检查当前用户是否在管理组c#

c++ - 运行时类型信息(为什么这段代码不起作用)

c# - 继承问题,从继承类的某些数据上获取 NULL

c++ - 在 C++ 继承中,当指向基类的指针对象指向派生类时,不调用派生类析构函数

.net - 是否可以覆盖 VB.NET/VS2008 中注释的自动缩进?

c++ - 有没有什么工具可以只翻译代码中的注释