From 65fe0e8f626d4d8e96c3732aadc3a268d291d82b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 29 Apr 2019 09:31:34 -0400 Subject: [PATCH] string has value converter --- src/App/Utilities/StringHasValueConverter.cs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/App/Utilities/StringHasValueConverter.cs diff --git a/src/App/Utilities/StringHasValueConverter.cs b/src/App/Utilities/StringHasValueConverter.cs new file mode 100644 index 000000000..d21d809a2 --- /dev/null +++ b/src/App/Utilities/StringHasValueConverter.cs @@ -0,0 +1,24 @@ +using System; +using Xamarin.Forms; + +namespace Bit.App.Utilities +{ + public class StringHasValueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + if(targetType == typeof(bool) && value.GetType() == typeof(string)) + { + return !string.IsNullOrWhiteSpace((string)value); + } + throw new InvalidOperationException("The value must be a string with a boolean target."); + } + + public object ConvertBack(object value, Type targetType, object parameter, + System.Globalization.CultureInfo culture) + { + throw new NotSupportedException(); + } + } +}