Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NumericToBool.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 numerical value to a boolean. The result will be <c>false</c> if the given value is equal to zero, <c>true</c> otherwise.
10  /// </summary>
11  /// <remarks>Supported types are: <see cref="SByte"/>, <see cref="Int16"/>, <see cref="Int32"/>, <see cref="Int64"/>, <see cref="Byte"/>, <see cref="UInt16"/>, <see cref="UInt32"/>, <see cref="UInt64"/></remarks>
12  public class NumericToBool : OneWayValueConverter<NumericToBool>
13  {
14  /// <inheritdoc/>
15  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16  {
17  if (value is sbyte) return ((sbyte)value) != 0;
18  if (value is short) return ((short)value) != 0;
19  if (value is int) return ((int)value) != 0;
20  if (value is long) return ((long)value) != 0;
21  if (value is byte) return ((byte)value) != 0;
22  if (value is ushort) return ((ushort)value) != 0;
23  if (value is uint) return ((uint)value) != 0;
24  if (value is ulong) return ((ulong)value) != 0;
25  throw new ArgumentException("value is not a numeric type");
26  }
27  }
28 }
This converter will convert a numerical value to a boolean. The result will be false if the given val...
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)