我有一个使用IList<T>作为参数的方法。我需要检查该T对象的类型是什么,并基于该对象执行某些操作。我试图使用该T值,但编译器不允许使用它。我的解决方案如下:
private static string BuildClause<T>(IList<T> clause)
{
    if (clause.Count > 0)
    {
        if (clause[0] is int || clause[0] is decimal)
        {
           //do something
        }
        else if (clause[0] is String)
        {
           //do something else
        }
        else if (...) //etc for all the types
        else
        {
           throw new ApplicationException("Invalid type");
        }
    } 
}
必须有一个更好的方法来做到这一点。有什么办法可以检查T传入的类型,然后使用switch语句?