Get All Values of Enums
<p>I want to create a method that takes in an <code>Enum</code> type, and returns all the enum inside it in an array, how to create such a funciton?</p>

<p>Take for example, I have two enums:</p>

<pre><code>public enum Family
{ 
   Brother,
   Sister,
   Father
}

public enum CarType
{ 
   Volkswagen,
   Ferrari,
   BMW
}
</code></pre>

<p>How to create a function <code>GetEnumList</code> so that it returns</p>

<ol>
<li><code>{Family.Brother, Family.Sister, Family.Father}</code> for the first case.</li>
<li><code>{CarType.Volkswagen, CarType.Ferrari, CarType.BMW}</code> for the second case.</li>
</ol>

<p>I tried :</p>

<pre><code>    private static List&lt;T&gt; GetEnumList&lt;T&gt;()
    {
        var enumList = Enum.GetValues(typeof(T))
            .Cast&lt;T&gt;().ToList();
        return enumList;
    }
</code></pre>

<p>But I got an <code>InvalidOperationException</code>:</p>

<pre><code>System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
    at System.Reflection.RuntimeMethodInfo.ThrowNoInvokeException()
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
</code></pre>

<p><strong>Edit: The above code is working fine-- the reason I got an exception was because profiler caused me the bug. Thank you all for your solution.</strong> </p>
