Cleanup unusable classes

This commit is contained in:
2024-09-02 21:03:52 +02:00
parent 545dc08897
commit 6a8c290adc
4 changed files with 16 additions and 35 deletions
@@ -1,27 +0,0 @@
using System.Extensions;
using System.Runtime.CompilerServices;
namespace Net.Maui.Extensions;
public abstract class ContentPageWithContext<T> : ContentPage
{
public new T BindingContext
{
get => base.BindingContext.Cast<T>();
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);
}
}
+1 -7
View File
@@ -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<TMainPage>");
}
.FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMainPagePresenter<>)) ?? throw new InvalidOperationException($"{currentType.Name} must implement IMainPagePresenter<TMainPage>");
var mainPageType = interfaceType.GetGenericArguments()[0];
this.navigationService.Cast<NavigationService>().SetNavigationRoot(this, mainPageType);
}
@@ -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<T>(this ContentPage contentPage)
where T : INotifyPropertyChanged
{
return contentPage.ThrowIfNull().BindingContext.Cast<T>();
}
}
@@ -20,7 +20,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<Version>0.2.7</Version>
<Version>0.2.8</Version>
<Authors>Alexandru Macocian</Authors>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>