-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Design.Generic.AvoidMethodWithUnusedGenericTypeRule(2.10)
Assembly: Gendarme.Rules.Design.Generic
Version: 2.10
This method will fire if a generic method does not use all of its generic type parameters in the formal parameter list. This usually means that either the type parameter is not used at all in which case it should be removed or that it's used only for the return type which is problematic because that prevents the compiler from inferring the generic type when the method is called which is confusing to many developers.
Bad example:
public class Bad {
public string ToString<T> ()
{
return typeof (T).ToString ();
}
static void Main ()
{
// the compiler can't infer int so we need to supply it ourselves
Console.WriteLine (ToString<int> ());
}
}
Good example:
public class Good {
public string ToString<T> (T obj)
{
return obj.GetType ().ToString ();
}
static void Main ()
{
Console.WriteLine (ToString (2));
}
}
- This rule is available since Gendarme 2.2
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!