Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
BoolToParam.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 boolean to the object given in parameter if its true, and to null if it's false.
10  /// <see cref="ConvertBack"/> is supported and will return whether the given object is non-null
11  /// </summary>
12  public class BoolToParam : ValueConverterBase<BoolToParam>
13  {
14  /// <inheritdoc/>
15  public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16  {
17  bool result = System.Convert.ToBoolean(value);
18  return result ? parameter : null;
19  }
20 
21  /// <inheritdoc/>
22  public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23  {
24  return value != null;
25  }
26  }
27 }
This converter will convert a boolean to the object given in parameter if its true, and to null if it's false. ConvertBack is supported and will return whether the given object is non-null
Definition: BoolToParam.cs:12
override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Definition: BoolToParam.cs:22
override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Definition: BoolToParam.cs:15