c# typeof applied to generic parameter supertype
<p>I have a method, it doesn't have any T parameters. </p>

<p>Unfortunately, C# typeof operator doesnt work on generics as shown bellow.</p>

<pre><code>public static string ToString(object obj)
{
    if (obj.GetType() == typeof(List&lt;object&gt;))
    {
        return "Bug: Never called";
    }
    if (obj.GetType() == typeof(List&lt;int&gt;))
    {
        return "Method only works for int lists";
    }
    return "";
}
</code></pre>

<p>Expected output: ToString(List of ints) would return "Bug: Never Called".</p>

<p>Actual output: "Method only works for int lists"</p>

<p>This worked perfectly fine in Java. You will say that generics in c# don't support this. How can I restructure my code to make "ToString(object)" method work for a list of objects? </p>

<p>Requirements : You cannot modify the method's signature, only its implementation.</p>

<p>Unfortunately you cannot make "int" class implement an interface. Since int class was written by Microsoft. As such I cannot add a visitor pattern on int type.</p>