Application of generics
I've posted recently a question "Generic collection population from database". Let's assume that population has happened whether using reflection or SQL 2005 object type feature.
Now we do have a generic list and I want to a have generic method which emits html table as return string after traversing a list.
public static string GenerateHtmlTable<T> (List<T> list, string tableName)
{
foreach (T t in list)
{
System.Diagnostics.Debug.WriteLine(t.ToString());
}
System.Diagnostics.Debug.WriteLine("============== =============");
List<T>.Enumerator row = list.GetEnumerator();
while (row.MoveNext())
{
System.Diagnostics.Debug.WriteLine(t.ToString());
}
return htmlTable ;
}
The only solution I was able to come up with is to override ToString to return HTML row or CSV which concatenation of class properties values. Any other ideas ?
TIA
Michael
|