Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.Cockpit.Query/TypeNameConverter.cs @ 4891

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

Integrated OKB clients for HL 3.3 (#1166)

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Data;
6
7namespace HeuristicLab.OKB.Cockpit.Query {
8  public class TypeNameConverter : IValueConverter {
9
10    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
11      return FormatType(value);
12    }
13
14    public static object FormatType(object value) {
15      Type type = value as Type;
16      if (type == null)
17        return "none";
18      StringBuilder sb = new StringBuilder();
19      if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {
20        sb.Append('?');
21        type = type.GetGenericArguments()[0];
22      }
23      if (type == typeof(Int32)) sb.Append("int");
24      if (type == typeof(Double)) sb.Append("double");
25      if (type == typeof(String)) sb.Append("string");
26      if (type == typeof(Guid)) sb.Append("Guid");
27      if (type == typeof(DateTime)) sb.Append("DateTime");
28      return sb.ToString();
29    }
30
31    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
32      throw new NotImplementedException();
33    }
34
35  }
36}
Note: See TracBrowser for help on using the repository browser.