diff --git a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs index 9ce0a221c6..a693b4b2ff 100644 --- a/src/Sentry.Maui/Internal/PageNavigationExtensions.cs +++ b/src/Sentry.Maui/Internal/PageNavigationExtensions.cs @@ -4,6 +4,7 @@ namespace Sentry.Maui.Internal; internal static class PageNavigationExtensions { +#if !NET10_0_OR_GREATER private static readonly PropertyInfo? DestinationPageProperty; private static readonly PropertyInfo? PreviousPageProperty; @@ -15,22 +16,29 @@ static PageNavigationExtensions() return; } DestinationPageProperty = typeof(NavigatedFromEventArgs) - .GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); + .GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); PreviousPageProperty = typeof(NavigatedToEventArgs) - .GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); + .GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } +#endif /// - /// Reads the (internal) NavigatedFromEventArgs.DestinationPage property via reflection. - /// Note that this will return null if trimming is enabled. + /// Gets the destination page from navigation arguments. /// public static Page? GetDestinationPage(this NavigatedFromEventArgs eventArgs) => +#if NET10_0_OR_GREATER + eventArgs.DestinationPage; +#else DestinationPageProperty?.GetValue(eventArgs) as Page; +#endif /// - /// Reads the (internal) NavigatedFromEventArgs.PreviousPage property via reflection. - /// Note that this will return null if trimming is enabled. + /// Gets the previous page from navigation arguments. /// public static Page? GetPreviousPage(this NavigatedToEventArgs eventArgs) => +#if NET10_0_OR_GREATER + eventArgs.PreviousPage; +#else PreviousPageProperty?.GetValue(eventArgs) as Page; +#endif } diff --git a/test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs b/test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs index d361e5d340..aa635f76d6 100644 --- a/test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs +++ b/test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs @@ -88,11 +88,8 @@ public void Page_NavigatedTo_AddsBreadcrumb() Assert.Equal(MauiEventsBinder.NavigationType, crumb.Type); Assert.Equal(MauiEventsBinder.NavigationCategory, crumb.Category); crumb.Data.Should().Contain($"{nameof(Page)}.Name", "page"); -#if !NET10_0 - // TODO: Work out why these are missing in .NET 10 crumb.Data.Should().Contain("PreviousPage", nameof(Page)); crumb.Data.Should().Contain("PreviousPage.Name", "otherPage"); -#endif } [Fact]