Skip to content

Instantly share code, notes, and snippets.

@MatthewSteeples
Created October 17, 2012 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewSteeples/3905438 to your computer and use it in GitHub Desktop.
Save MatthewSteeples/3905438 to your computer and use it in GitHub Desktop.
ValueConverter to convert an IEnumerable of anything into a string with custom separator
using System;
using System.Collections;
using System.Linq;
using System.Windows.Data;
namespace LedgerscopeApplication.ValueConverters
{
public class EnumerableToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (parameter == null)
parameter = Environment.NewLine;
var val = value as IEnumerable;
if (val != null)
{
var retVal = string.Join(parameter.ToString(), val.OfType<object>().Select(a => a.ToString()));
return retVal;
}
else
{
return string.Empty;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment