를 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문 을 사용할 수있는 방법이 있습니까?