Skip to content

Commit

Permalink
Add the InverseBooleanConverter Class.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoYang06 committed Aug 30, 2021
1 parent 4a638b4 commit 49b9ced
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Source/Wif.Infrastructure/Converters/InverseBooleanConverter.cs
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;
}
}
}

0 comments on commit 49b9ced

Please sign in to comment.