StyleCop SA1620,我不知道如何根据自己的喜好来解析我的XML评论

Dan*_*ler 6 c# stylecop

我有以下代码w/comments :(它确实编译)

/// <summary>
/// return a passing result of a particular type
/// </summary>
/// <typeparam name="T">Type of the value to be returned</typeparam>
/// <param name="value">the value to be returned</param>
/// <returns>a passing result</returns>
public static Result<T> Pass(T value)
{
    return new Result<T>()
    {
        Passed = true,
        Value = value
    };
}
Run Code Online (Sandbox Code Playgroud)

我收到以下警告:

警告1 SA1620:CSharp.Documentation:文档标题中的typeparam标记必须与方法的泛型类型匹配.

我确实查看了此错误的帮助页面,其中给出了以下解释:

要修复违反此规则的行为,请为元素上的每个泛型类型参数添加并填写一个标记,并确保标记的显示顺序与元素的类型参数相同.

它提供了示例代码:

/// <summary>
/// A sample generic class.
/// </summary>
/// <typeparam name="S">The first generic type parameter.</typeparam>
/// <typeparam name="T">The second generic type parameter.</typeparam>
public class Class1<S, T>
{ 
}
Run Code Online (Sandbox Code Playgroud)

我没有看到任何关于我的东西违反它所显示的标准,我尝试了各种奇怪的事情,但我不知道我应该在这里做什么.

Dam*_*ver 8

这可以编译的唯一方法是这个方法是否在class泛型中T.此方法没有任何类型参数.如果它是通用的,那么在方法名称后面会有类型参数:

public static Result<T> Pass<T>(T value)
{
    return new Result<T>()
    {
        Passed = true,
        Value = value
    };
}
Run Code Online (Sandbox Code Playgroud)

但是你的方法并非如此.所以一定是:

class SomeClass<T>
{
  public static Result<T> Pass(T value)
  {
      return new Result<T>()
      {
          Passed = true,
          Value = value
      };
  }
}
Run Code Online (Sandbox Code Playgroud)

有关type参数的任何文档都属于类级别.例如:

/// <summary>
/// This is a result class
/// </summary>
/// <typeparam name="T">Type of the value to be returned</typeparam>
public class Result<T>
{
    public bool Passed { get; set; }
    public T Value { get; set; }
    /// <summary>
    /// return a passing result of a particular type
    /// </summary>
    /// <param name="value">the value to be returned</param>
    /// <returns>a passing result</returns>
    public static Result<T> Pass(T value)
    {
        return new Result<T>()
        {
            Passed = true,
            Value = value
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @ WarpWars.Net - 我所说的是`<typeparam>`元素属于*class*的文档,并且*方法的文档中应该有**no**`<typeparam>`元素*. (3认同)