Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.Cockpit.Query/ListFormatter.cs @ 5982

Last change on this file since 5982 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Data;
6using System.Windows;
7using System.Collections;
8using System.Text.RegularExpressions;
9
10namespace HeuristicLab.OKB.Cockpit.Query {
11  public class ListFormatter : IValueConverter {
12
13    private Regex separator = new Regex(@"\s*,\s*");
14    public Regex Separator {
15      get {
16        return separator;
17      }
18      set {
19        separator = value;
20      }
21    }
22
23    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
24      IList lst = value as IList;
25      if (lst == null)
26        return value;
27      return string.Join(", ", lst.Cast<object>().Select(v => v.ToString()).ToArray());
28    }
29
30    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
31      string s = value as string;
32      if (string.IsNullOrEmpty(s))
33        return null;
34      return separator.Split((string)value).Cast<object>().ToList();
35    }
36
37  }
38}
Note: See TracBrowser for help on using the repository browser.