Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CharToUnicode.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Globalization;
5 
6 namespace SiliconStudio.Presentation.ValueConverters
7 {
8  /// <summary>
9  /// This converter will convert a <see cref="char"/> value to the integer representation of its unicode value.
10  /// <see cref="ConvertBack"/> is supported and will return the default char value if the given integer value can't be converted.
11  /// </summary>
12  public class CharToUnicode : ValueConverterBase<CharToUnicode>
13  {
14  /// <inheritdoc/>
15  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16  {
17  var unicodeValue = System.Convert.ToInt32(value);
18  return unicodeValue;
19  }
20 
21  /// <inheritdoc/>
22  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23  {
24  try
25  {
26  var charValue = System.Convert.ToChar(System.Convert.ToInt32(value));
27  return charValue;
28  }
29  catch (Exception)
30  {
31  return default(char);
32  }
33  }
34  }
35 }
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
This converter will convert a char value to the integer representation of its unicode value...
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)