Created
October 17, 2012 13:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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