I have an extension method to convert a general list to a string.
public static string ConvertToString<T>(this IList<T> list) { StringBuilder sb = new StringBuilder(); foreach (T item in list) { sb.Append(item.ToString()); } return sb.ToString(); }
I have an object that has an object of type that contains a list; the list can be List<string> , List<int> , List<ComplexType> any type of list.
Is there a way to detect that this object is a shared list and therefore is discarded into this type of generic type to call the ConvertToString method?
//ignore whats happening here //just need to know its an object which is actually a list object o = new List<int>() { 1, 2, 3, 4, 5 }; if (o is of type list) { string value = (cast o to generic type).ConvertToString(); }
David
source share