Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

ValueConverter to convert an IEnumerable of anything into a string with custom separator

View EnumerableToTextConverter.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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
Something went wrong with that request. Please try again.