Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Data;
|
---|
6 |
|
---|
7 | namespace 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.