Extension method to list enum values I have the following enum extension method:

public static IList&lt;SelectListItem&gt; SelectListFor&lt;T&gt;()
{
  Type enumType = typeof(T);

  if (enumType.IsEnum)
  {
    return Enum.GetValues(enumType)
    .Cast&lt;int&gt;()
    .Where(i =&gt; !i.Equals(0))
    .Select(e =&gt; new SelectListItem()
            {
            Value = e.ToString(),
      Text = GetDisplayName(enumType, Enum.GetName(enumType, e))
    })
    .ToList();
  }

  return null;
}


I can call this by doing

EnumExtensions.SelectListFor&lt;BrochureTypes&gt;()


And it will allow me to create a drop down list for the values in my BrochureTypes enum

However, when I compile the code, I get the following warning:


  CA1004    Consider a design where 'EnumExtensions.SelectListFor()' doesn't require explicit type parameter 'T' in any call to it.  


Can I somehow change the above code to overcome this warning? Or should I just suppress the warning?
As written in the relative MSDN page, the cause of the warning is 


  The parameter signature of an externally visible generic method does not contain types that correspond to all the type parameters of the method.


Looking at your code, you get the type of the generic param into the method body (which can be seen also as a violation of the Separation of Concerns principle). In order to solve the issue, you can pass the type as a parameter. The resulting code should be something like the following:

public static IList&lt;SelectListItem&gt; SelectListFor(Type enumType)
{
    if (enumType.IsEnum)
    {
        return Enum.GetValues(enumType)
            .Cast&lt;int&gt;()
            .Where(i =&gt; !i.Equals(0))
            .Select(e =&gt; new SelectListItem()
            {
                Value = e.ToString(),
                Text = GetDisplayName(enumType, Enum.GetName(enumType, e))
            })
            .ToList();
    }

    return null;
}


and can be called in the following way:

EnumExtensions.SelectListFor(typeof(BrochureTypes))


As an alternative, you can make it an extension method of the Type class, and I'd suggest a rename of the method in this case:

public static IList&lt;SelectListItem&gt; GetSelectList(this Type enumType)
{
    if (enumType.IsEnum)
    {
        return Enum.GetValues(enumType)
            .Cast&lt;int&gt;()
            .Where(i =&gt; !i.Equals(0))
            .Select(e =&gt; new SelectListItem()
            {
                Value = e.ToString(),
                Text = GetDisplayName(enumType, Enum.GetName(enumType, e))
            })
            .ToList();
    }

    return null;
}


and call it like this:

(typeof(BrochureTypes)).GetSelectList();


or:

enumInstance.GetType().GetSelectList();