A lot of times in the applications we require to pass comma separated values to the stored procedures, these values are contained in a custom object IList or IList<string> type.

/// <summary>
/// Converts a list item property name value to comma seperated values
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Items"></param>
/// <param name="PropertyName"></param>
/// <returns></returns>
public static string ConvertTo<T>(IList<T> Items, string PropertyName) 
{    
    StringBuilder builder = new StringBuilder();    
    Type entityType = typeof(T);     

    // iterate through the property    
    foreach (T Item in Items)    
    {        
        if (string.IsNullOrEmpty(PropertyName))            
            builder.Append(Item.ToString()).Append(",");        
        else // get the value of the property name passed            
            builder.Append(entityType.GetProperty(PropertyName).GetValue(Item, null).ToString()).Append(",");    
    }     
    
    return builder.ToString().TrimEnd(new char[] { ',' });
}