简体   繁体   English

如何使用相同的 XML 注释记录重载方法?

[英]How to document overloaded methods with the same XML comments?

I know there are questions like this, but they're old.我知道有这样的问题,但它们已经过时了。 So I'm creating a new one.所以我正在创建一个新的。

At the moment when there are 3 overloaded methods I have to do this:在有 3 个重载方法时,我必须这样做:

/// <summary>
/// Description that described summary of an overloaded method.
/// </summary>
/// <param name="fileName">Description that describes filename parameter</param>
/// <param name="options">Description that describes options parameter</param>
/// <returns>Description of what method returns</returns>
public bool ReadFrom(string fileName, ReaderOptions options = null) {
    return false;
}

/// <summary>
/// Description that described summary of an overloaded method.
/// </summary>
/// <param name="stream">Description that describes stream parameter</param>
/// <param name="options">Description that describes options parameter</param>
/// <returns>Description of what method returns</returns>
public bool ReadFrom(Stream stream, ReaderOptions options = null) {
    return false;
}

/// <summary>
/// Description that described summary of an overloaded method.
/// </summary>
/// <param name="rawData">Description that describes rawData parameter</param>
/// <param name="options">Description that describes options parameter</param>
/// <returns>Description of what method returns</returns>
public bool ReadFrom(byte[] rawData, ReaderOptions options = null) {
    return false;
}

And I would like to have something like this:我想要这样的东西:

#region overloadedReadFromMethods
/// <summary>
/// Description that described summary of an overloaded method.
/// </summary>
/// <param name="fileName">Description that describes filename parameter</param>
/// <param name="options">Description that describes options parameter</param>
/// <returns>Description of what method returns</returns>
public bool ReadFrom(string fileName, ReaderOptions options = null) {
    return false;
}

/// <param name="stream">Description that describes stream parameter</param>
public bool ReadFrom(Stream stream, ReaderOptions options = null) {
    return false;
}

/// <param name="rawData">Description that describes rawData parameter</param>
/// <returns>Even considering that returns tag is present on the first overloaded method,
/// this overloaded method shows this specific description.
/// </returns>
public bool ReadFrom(byte[] rawData, ReaderOptions options = null) {
    return false;
}
#endregion overloadedReadFromMethods

So the first overloaded method describes default description and then methods below can override it with their own descriptions.所以第一个重载方法描述了默认描述,然后下面的方法可以用自己的描述覆盖它。 I want it to show in Visual Studio's IntelliSense.我希望它显示在 Visual Studio 的 IntelliSense 中。

I think the extra work to document each method is necessary because they all have different signatures.我认为记录每种方法的额外工作是必要的,因为它们都有不同的签名。 Methods have different <param></param>方法有不同的<param></param>

InheritDoc is a package that can be used to inherit xml docs. InheritDoc是一个可用于继承 xml 文档的包。

TLDR - It's not possible TLDR - 这是不可能的

Long story short, as was the case in the past, you still cannot re-use comments this way.长话短说,就像过去一样,您仍然无法以这种方式重复使用评论。

Some interesting ideas here 这里有一些有趣的想法

  1. Create one function with optional parameters.创建一个带有可选参数的函数。 While this would mitigate the problem, I find that optional parameters are sometimes incovenient themselves as they overcomplicate the logic inside and make unit testing very difficult.虽然这可以缓解问题,但我发现可选参数本身有时不方便,因为它们使内部逻辑过于复杂并使单元测试变得非常困难。 Overaloading in your case make sense, so this solution does not apply.在您的情况下超载是有道理的,因此此解决方案不适用。

  2. Use the <overloads> comment.使用<overloads>注释。 I can't see it in the official documentation though虽然我在官方文档中看不到它

  3. Use the <see> and <seealso> xml tag to use reference使用<see><seealso> xml 标签来使用引用

Use the <include> tag使用<include>标签

This is still not a solution but it allows you to have separate xml documents and handle overall.这仍然不是解决方案,但它允许您拥有单独的 xml 文档并整体处理。 include documentation 包括文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM