Domanda

I have the following code w/comments: (It does compile)

/// <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
    };
}

I get the following warning with it:

Warning 1 SA1620 : CSharp.Documentation : The typeparam tags in the documentation header must match the generic types for the method.

I did look at the help page for this error, which gives this explanation:

To fix a violation of this rule, add and fill-in one tag for each generic type parameter on the element, and make sure that the tags appear in the same order as the element’s type parameters.

And it has provided sample code:

/// <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>
{ 
}

I don't see anything about mine that breaks the standards it is showing, and I have tried various odd things, but I have no real idea of what I'm supposed to do here.

È stato utile?

Soluzione

The only way that this can compile is if this method is inside a class that is generic in T. This method doesn't have any type parameters. If it was generic, there would be type parameters after the name of the method:

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

But that's not the case with your method. So it must be:

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

And any documentation about the type parameter belongs up at the class level. E.g.:

/// <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
        };
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top