-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the InverseBooleanConverter Class.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Source/Wif.Infrastructure/Converters/InverseBooleanConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Frontier.Wif.Infrastructure.MarkupExtensions; | ||
|
||
namespace Frontier.Wif.Infrastructure.Converters | ||
{ | ||
/// <summary> | ||
/// 接受一个bool值,并返回其反值。 | ||
/// </summary> | ||
public class InverseBooleanConverter : MarkupConverter | ||
{ | ||
/// <summary> | ||
/// 将一个布尔值转换为其反值。 | ||
/// </summary> | ||
/// <param name="value">The source value.</param> | ||
/// <param name="targetType">The parameter is not used.</param> | ||
/// <param name="parameter">The parameter is not used.</param> | ||
/// <param name="culture">The parameter is not used.</param> | ||
/// <returns>The inverted boolean value.</returns> | ||
protected override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
if (value == null) | ||
{ | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
var boolValue = (bool)value; | ||
return !boolValue; | ||
} | ||
|
||
/// <summary> | ||
/// 将一个布尔值转换为其反值。 | ||
/// </summary> | ||
/// <param name="value">The parameter is not used.</param> | ||
/// <param name="targetType">The parameter is not used.</param> | ||
/// <param name="parameter">The parameter is not used.</param> | ||
/// <param name="culture">The parameter is not used.</param> | ||
/// <returns>The parameter is not used.</returns> | ||
protected override object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
if (value == null) | ||
{ | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
|
||
var boolValue = (bool)value; | ||
return !boolValue; | ||
} | ||
} | ||
} |