From 6a8c290adc2ece4800c0d14304ce25d9e8d25566 Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Mon, 2 Sep 2024 21:03:52 +0200 Subject: [PATCH] Cleanup unusable classes --- Net.Maui.Extensions/ContentPageWithContext.cs | 27 ------------------- Net.Maui.Extensions/ExtendedApplication.cs | 8 +----- .../Extensions/ContentPageExtensions.cs | 14 ++++++++++ .../Net.Maui.Extensions.csproj | 2 +- 4 files changed, 16 insertions(+), 35 deletions(-) delete mode 100644 Net.Maui.Extensions/ContentPageWithContext.cs create mode 100644 Net.Maui.Extensions/Extensions/ContentPageExtensions.cs diff --git a/Net.Maui.Extensions/ContentPageWithContext.cs b/Net.Maui.Extensions/ContentPageWithContext.cs deleted file mode 100644 index 480b86c..0000000 --- a/Net.Maui.Extensions/ContentPageWithContext.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Extensions; -using System.Runtime.CompilerServices; - -namespace Net.Maui.Extensions; - -public abstract class ContentPageWithContext : ContentPage -{ - public new T BindingContext - { - get => base.BindingContext.Cast(); - set => base.BindingContext = value; - } - - protected override void OnPropertyChanged([CallerMemberName] string? propertyName = null) - { - if (propertyName == BindingContextProperty.PropertyName) - { - if (base.BindingContext is not T) - { - throw new InvalidOperationException($"Binding context has been set to a value of type {base.BindingContext.GetType().Name}. Only values of type {typeof(T).Name}"); - } - - } - - base.OnPropertyChanged(propertyName); - } -} \ No newline at end of file diff --git a/Net.Maui.Extensions/ExtendedApplication.cs b/Net.Maui.Extensions/ExtendedApplication.cs index f00452b..5c482d8 100644 --- a/Net.Maui.Extensions/ExtendedApplication.cs +++ b/Net.Maui.Extensions/ExtendedApplication.cs @@ -22,13 +22,7 @@ public abstract class ExtendedApplication : Application // Find the interface that implements IMainPagePresenter<> var interfaceType = currentType .GetInterfaces() - .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMainPagePresenter<>)); - - if (interfaceType is null) - { - throw new InvalidOperationException($"{currentType.Name} must implement IMainPagePresenter"); - } - + .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMainPagePresenter<>)) ?? throw new InvalidOperationException($"{currentType.Name} must implement IMainPagePresenter"); var mainPageType = interfaceType.GetGenericArguments()[0]; this.navigationService.Cast().SetNavigationRoot(this, mainPageType); } diff --git a/Net.Maui.Extensions/Extensions/ContentPageExtensions.cs b/Net.Maui.Extensions/Extensions/ContentPageExtensions.cs new file mode 100644 index 0000000..3b51712 --- /dev/null +++ b/Net.Maui.Extensions/Extensions/ContentPageExtensions.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using System.Core.Extensions; +using System.Extensions; + +namespace Net.Maui.Extensions.Extensions; + +public static class ContentPageExtensions +{ + public static T GetBindingContext(this ContentPage contentPage) + where T : INotifyPropertyChanged + { + return contentPage.ThrowIfNull().BindingContext.Cast(); + } +} diff --git a/Net.Maui.Extensions/Net.Maui.Extensions.csproj b/Net.Maui.Extensions/Net.Maui.Extensions.csproj index 30bfeff..0f525b4 100644 --- a/Net.Maui.Extensions/Net.Maui.Extensions.csproj +++ b/Net.Maui.Extensions/Net.Maui.Extensions.csproj @@ -20,7 +20,7 @@ enable enable true - 0.2.7 + 0.2.8 Alexandru Macocian LICENSE true