From 865deaf4017c11ac3061704172f1b7d235003e31 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 30 Apr 2019 09:50:24 -0400 Subject: [PATCH] null converters --- src/App/Utilities/IsNotNullConverter.cs | 24 ++++++++++++++++++++++++ src/App/Utilities/IsNullConverter.cs | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/App/Utilities/IsNotNullConverter.cs create mode 100644 src/App/Utilities/IsNullConverter.cs diff --git a/src/App/Utilities/IsNotNullConverter.cs b/src/App/Utilities/IsNotNullConverter.cs new file mode 100644 index 000000000..d692e813c --- /dev/null +++ b/src/App/Utilities/IsNotNullConverter.cs @@ -0,0 +1,24 @@ +using System; +using Xamarin.Forms; + +namespace Bit.App.Utilities +{ + public class IsNotNullConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + if(targetType == typeof(bool)) + { + return value != null; + } + throw new InvalidOperationException("The target must be a boolean."); + } + + public object ConvertBack(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + throw new NotSupportedException(); + } + } +} diff --git a/src/App/Utilities/IsNullConverter.cs b/src/App/Utilities/IsNullConverter.cs new file mode 100644 index 000000000..99ac14d1c --- /dev/null +++ b/src/App/Utilities/IsNullConverter.cs @@ -0,0 +1,24 @@ +using System; +using Xamarin.Forms; + +namespace Bit.App.Utilities +{ + public class IsNullConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + if(targetType == typeof(bool)) + { + return value == null; + } + throw new InvalidOperationException("The target must be a boolean."); + } + + public object ConvertBack(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + throw new NotSupportedException(); + } + } +}