basically I\'m building a very generic T4 template and one of the things I need it to do is say print variable.ToString(). However, I want it to evaluate lists and
variable.ToString()
If you don't care about object type and you are not in Generic method in C# 7.0+
if (item is IEnumerable enumVar) { foreach (var e in enumVar) { e.ToString(); } }
In C# < 7.0
if (item is IEnumerable) { var enumVar = item as IEnumerable; foreach (var e in enumVar) { e.ToString(); } //or you can cast an array to set values, //since IEnumerable won't let you, unless you cast to IList :) //but array version here //https://stackoverflow.com/a/9783253/1818723 }