Is it a good idea to use an extension method on the Object class?
I was wondering if by registering this method if you were incurring a performance penalty as it would b
The following example demonstrates the extension method in use.
namespace NamespaceName
{
public static class CommonUtil
{
public static string ListToString(this IList list)
{
StringBuilder result = new StringBuilder("");
if (list.Count > 0)
{
result.Append(list[0].ToString());
for (int i = 1; i < list.Count; i++)
result.AppendFormat(", {0}", list[i].ToString());
}
return result.ToString();
}
}
}
The following example demonstrates how this method can be used.
var _list = DataContextORM.ExecuteQuery("Select name from products").ToList();
string result = _list.ListToString();