相关疑难解决方法(0)

在C#中同步接口和实现注释的方法

是否有自动方式在界面与其实现之间同步注释?我目前正在记录它们,并且不想手动保持它们同步.

更新:

考虑以下代码:

interface IFoo{
    /// <summary>
    /// Commenting DoThis method
    /// </summary>
    void DoThis();
}
class Foo : IFoo {
    public void DoThis();
}
Run Code Online (Sandbox Code Playgroud)

当我创建这样的类:

IFoo foo=new Foo();
foo.DoThis();//comments are shown in intellisense
Run Code Online (Sandbox Code Playgroud)

这里的评论没有显示:

Foo foo=new Foo();
foo.DoThis();//comments are not shown in intellisense
Run Code Online (Sandbox Code Playgroud)

<inheritDoc/>标签将完全产生沙堡的文件,但它并没有在智能感知提示工作.

请分享您的想法.

谢谢.

c# documentation xml-documentation

92
推荐指数
3
解决办法
3万
查看次数

您应该为Interfaces,具体实现或两者编写XML注释吗?

标题基本概括了所有内容.我在哪里应用我的XML注释?我应该在界面中添加更通用的XML注释,并在实现类中添加更具描述性的注释吗?像这样:

public interface IObjectRepository
{
    /// <summary>
    ///    Returns an object from the respository that contains the specified ID.
    /// </summary>
    Object GetObject(int Id);
}

public ObjectRepository : IObjectRepository
{
    /// <summary>
    ///    Retrieves an object from the database that contains the specified ID.
    /// </summary>
    public Object GetObject(int Id)
    {
        Object myData = // Get from DB code.
        return myData;
    }
}
Run Code Online (Sandbox Code Playgroud)

<param>为简单起见,我没有包括在内.

这是一个很好的评论做法还是有不同的方式?我是否只是跳过评论界面?任何帮助表示赞赏.

c# documentation comments interface xml-comments

13
推荐指数
1
解决办法
4334
查看次数