From 44bb7f0adb0e5d4706ce5488b362e16173015e62 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Wed, 9 Feb 2022 20:14:39 -0800 Subject: [PATCH 1/6] Rename `IsStringNullOrEmptyConverter` and `IsStringNotNullOrEmptyConverter` --- .../Converters/ConvertersGalleryViewModel.cs | 4 ++-- .../Converters/IsNotNullOrEmptyConverter_Tests.cs | 4 ++-- .../Converters/IsNullOrEmptyConverter_Tests.cs | 4 ++-- ...ed.cs => IsStringNotNullOrEmptyConverter.shared.cs} | 8 ++++---- ...erter.shared.cs => IsStringNullOrEmptyConverter.cs} | 10 ++++------ 5 files changed, 14 insertions(+), 16 deletions(-) rename src/CommunityToolkit.Maui/Converters/{IsNotNullOrEmptyConverter.shared.cs => IsStringNotNullOrEmptyConverter.shared.cs} (75%) rename src/CommunityToolkit.Maui/Converters/{IsNullOrEmptyConverter.shared.cs => IsStringNullOrEmptyConverter.cs} (72%) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ConvertersGalleryViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ConvertersGalleryViewModel.cs index de95d1df7c..7853ab0699 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ConvertersGalleryViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/ConvertersGalleryViewModel.cs @@ -11,10 +11,10 @@ public ConvertersGalleryViewModel() SectionModel.Create(nameof(BoolToObjectConverter), "A converter that allows users to convert a bool value binding to a specific object."), - SectionModel.Create(nameof(IsNullOrEmptyConverter), + SectionModel.Create(nameof(IsStringNullOrEmptyConverter), "A converter that allows users to convert an incoming binding to a bool value. This value represents if the incoming binding value is null or empty."), - SectionModel.Create(nameof(IsNotNullOrEmptyConverter), + SectionModel.Create(nameof(IsStringNotNullOrEmptyConverter), "A converter that allows users to convert an incoming binding to a bool value. This value represents if the incoming binding value is Not null or empty."), SectionModel.Create(nameof(InvertedBoolConverter), diff --git a/src/CommunityToolkit.Maui.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit.Maui.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs index 1111233b1b..de4994b1e9 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Converters/IsNotNullOrEmptyConverter_Tests.cs @@ -8,12 +8,12 @@ public class IsNotNullOrEmptyConverter_Tests : BaseTest { [Theory] [InlineData("Test", true)] - [InlineData(typeof(IsNotNullOrEmptyConverter), true)] + [InlineData(typeof(IsStringNotNullOrEmptyConverter), true)] [InlineData(null, false)] [InlineData("", false)] public void IsNotNullOrEmptyConverter(object value, bool expectedResult) { - var isNotNullOrEmptyConverter = new IsNotNullOrEmptyConverter(); + var isNotNullOrEmptyConverter = new IsStringNotNullOrEmptyConverter(); var result = (bool)isNotNullOrEmptyConverter.Convert(value, typeof(IsNotNullOrEmptyConverter_Tests), null, CultureInfo.CurrentCulture); diff --git a/src/CommunityToolkit.Maui.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs b/src/CommunityToolkit.Maui.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs index bb38d6af9b..ba691e05bd 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Converters/IsNullOrEmptyConverter_Tests.cs @@ -10,10 +10,10 @@ public class IsNullOrEmptyConverter_Tests : BaseTest [InlineData(null, true)] [InlineData("", true)] [InlineData("Test", false)] - [InlineData(typeof(IsNullOrEmptyConverter), false)] + [InlineData(typeof(IsStringNullOrEmptyConverter), false)] public void IsNullOrEmptyConverter(object value, bool expectedResult) { - var isNullOrEmptyConverter = new IsNullOrEmptyConverter(); + var isNullOrEmptyConverter = new IsStringNullOrEmptyConverter(); var result = (bool)isNullOrEmptyConverter.Convert(value, typeof(IsNotNullOrEmptyConverter_Tests), null, CultureInfo.CurrentCulture); diff --git a/src/CommunityToolkit.Maui/Converters/IsNotNullOrEmptyConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/IsStringNotNullOrEmptyConverter.shared.cs similarity index 75% rename from src/CommunityToolkit.Maui/Converters/IsNotNullOrEmptyConverter.shared.cs rename to src/CommunityToolkit.Maui/Converters/IsStringNotNullOrEmptyConverter.shared.cs index 41b7596aa4..1aa08b2455 100644 --- a/src/CommunityToolkit.Maui/Converters/IsNotNullOrEmptyConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/IsStringNotNullOrEmptyConverter.shared.cs @@ -7,10 +7,10 @@ namespace CommunityToolkit.Maui.Converters; /// /// Converts the incoming value to a indicating whether or not the value is not null and not empty. /// -public class IsNotNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter +public class IsStringNotNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter { /// - /// Converts the incoming value to a indicating whether or not the value is not null and not empty. + /// Converts the incoming string to a indicating whether or not the value is not null and not empty using string.IsNullOrEmpty. /// /// The value to convert. /// The type of the binding target property. This is not implemented. @@ -18,8 +18,8 @@ public class IsNotNullOrEmptyConverter : ValueConverterExtension, ICommunityTool /// The culture to use in the converter. This is not implemented. /// A indicating if the incoming value is not null and not empty. [return: NotNull] - public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) => - !IsNullOrEmptyConverter.ConvertInternal(value); + public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) + => value is string stringValue ? !string.IsNullOrEmpty(stringValue) : throw new ArgumentException("Binding must be of type string", nameof(value)); /// /// This method is not implemented and will throw a . diff --git a/src/CommunityToolkit.Maui/Converters/IsNullOrEmptyConverter.shared.cs b/src/CommunityToolkit.Maui/Converters/IsStringNullOrEmptyConverter.cs similarity index 72% rename from src/CommunityToolkit.Maui/Converters/IsNullOrEmptyConverter.shared.cs rename to src/CommunityToolkit.Maui/Converters/IsStringNullOrEmptyConverter.cs index 07efb7792c..020488217a 100644 --- a/src/CommunityToolkit.Maui/Converters/IsNullOrEmptyConverter.shared.cs +++ b/src/CommunityToolkit.Maui/Converters/IsStringNullOrEmptyConverter.cs @@ -7,10 +7,10 @@ namespace CommunityToolkit.Maui.Converters; /// /// Converts the incoming value to a indicating whether or not the value is null or empty. /// -public class IsNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter +public class IsStringNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkitValueConverter { /// - /// Converts the incoming value to a indicating whether or not the value is null or empty. + /// Converts the incoming string to a indicating whether or not the string is null and not empty using string.IsNullOrEmpty. /// /// The value to convert. /// The type of the binding target property. This is not implemented. @@ -18,7 +18,8 @@ public class IsNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkit /// The culture to use in the converter. This is not implemented. /// A indicating if the incoming value is null or empty. [return: NotNull] - public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) => ConvertInternal(value); + public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) + => value is string stringValue ? string.IsNullOrEmpty(stringValue) : throw new ArgumentException("Binding must be of type string", nameof(value)); /// /// This method is not implemented and will throw a . @@ -30,7 +31,4 @@ public class IsNullOrEmptyConverter : ValueConverterExtension, ICommunityToolkit /// N/A public object? ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotImplementedException(); - - internal static bool ConvertInternal(object? value) => - value == null || (value is string str && string.IsNullOrWhiteSpace(str)); } \ No newline at end of file From e99f0528dc8cb21c2f007a0e7757195b996e94cb Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Wed, 9 Feb 2022 20:42:48 -0800 Subject: [PATCH 2/6] Update Samples --- .../AppShell.xaml.cs | 4 +-- .../MauiProgram.cs | 4 +-- .../IsNotNullOrEmptyConverterPage.xaml | 34 ------------------- .../IsNotNullOrEmptyConverterPage.xaml.cs | 12 ------- .../IsNullOrEmptyConverterPage.xaml | 34 ------------------- .../IsNullOrEmptyConverterPage.xaml.cs | 12 ------- .../IsStringNotNullOrEmptyConverterPage.xaml | 34 +++++++++++++++++++ ...sStringNotNullOrEmptyConverterPage.xaml.cs | 12 +++++++ .../IsStringNullOrEmptyConverterPage.xaml | 34 +++++++++++++++++++ .../IsStringNullOrEmptyConverterPage.xaml.cs | 12 +++++++ .../Converters/ConvertersGalleryViewModel.cs | 4 +-- .../IsNotNullOrEmptyConverterViewModel.cs | 8 ----- .../IsNullOrEmptyConverterViewModel.cs | 28 --------------- ...sStringNotNullOrEmptyConverterViewModel.cs | 14 ++++++++ .../IsStringNullOrEmptyConverterViewModel.cs | 14 ++++++++ .../IsStringNotNullOrEmptyConverter.shared.cs | 6 +++- .../IsStringNullOrEmptyConverter.cs | 6 +++- 17 files changed, 136 insertions(+), 136 deletions(-) delete mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml delete mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml.cs delete mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNullOrEmptyConverterPage.xaml delete mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNullOrEmptyConverterPage.xaml.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsStringNotNullOrEmptyConverterPage.xaml create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsStringNotNullOrEmptyConverterPage.xaml.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsStringNullOrEmptyConverterPage.xaml create mode 100644 samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsStringNullOrEmptyConverterPage.xaml.cs delete mode 100644 samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/IsNotNullOrEmptyConverterViewModel.cs delete mode 100644 samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/IsNullOrEmptyConverterViewModel.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/IsStringNotNullOrEmptyConverterViewModel.cs create mode 100644 samples/CommunityToolkit.Maui.Sample/ViewModels/Converters/IsStringNullOrEmptyConverterViewModel.cs diff --git a/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs b/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs index f371b93c65..fda4d16a70 100644 --- a/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs +++ b/samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs @@ -46,8 +46,8 @@ public partial class AppShell : Shell { typeof(IndexToArrayItemConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IndexToArrayItemConverterPage)) }, { typeof(IntToBoolConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IntToBoolConverterPage)) }, { typeof(InvertedBoolConverterViewModel), (typeof(ConvertersGalleryPage), typeof(InvertedBoolConverterPage)) }, - { typeof(IsNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsNotNullOrEmptyConverterPage)) }, - { typeof(IsNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsNullOrEmptyConverterPage)) }, + { typeof(IsStringNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsStringNotNullOrEmptyConverterPage)) }, + { typeof(IsStringNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(IsStringNullOrEmptyConverterPage)) }, { typeof(ItemSelectedEventArgsConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ItemSelectedEventArgsConverterPage)) }, { typeof(ItemTappedEventArgsConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ItemTappedEventArgsConverterPage)) }, { typeof(ListIsNotNullOrEmptyConverterViewModel), (typeof(ConvertersGalleryPage), typeof(ListIsNotNullOrEmptyConverterPage)) }, diff --git a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs index a799627288..d1699e23f8 100644 --- a/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs +++ b/samples/CommunityToolkit.Maui.Sample/MauiProgram.cs @@ -35,8 +35,8 @@ public static MauiApp CreateMauiApp() builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); - builder.Services.AddTransient(); - builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml deleted file mode 100644 index bad89a1010..0000000000 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - -