Skip to content

Commit b72a798

Browse files
authored
fix: [.NET 10] PageNavigationExtensions updated for public Page properties (#5278)
* fixes 4578 starting with .NET 10 DestinationPage and PreviousPage in NavigatedFromEventArgs and NavigatedToEventArgs are no longer internal so no need for getting them via reflection in PageNavigationExtensions.
1 parent 2d437f2 commit b72a798

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/Sentry.Maui/Internal/PageNavigationExtensions.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Sentry.Maui.Internal;
44

55
internal static class PageNavigationExtensions
66
{
7+
#if !NET10_0_OR_GREATER
78
private static readonly PropertyInfo? DestinationPageProperty;
89
private static readonly PropertyInfo? PreviousPageProperty;
910

@@ -19,18 +20,25 @@ static PageNavigationExtensions()
1920
PreviousPageProperty = typeof(NavigatedToEventArgs)
2021
.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic);
2122
}
23+
#endif
2224

2325
/// <summary>
24-
/// Reads the (internal) NavigatedFromEventArgs.DestinationPage property via reflection.
25-
/// Note that this will return null if trimming is enabled.
26+
/// Gets the destination page from navigation arguments.
2627
/// </summary>
2728
public static Page? GetDestinationPage(this NavigatedFromEventArgs eventArgs) =>
29+
#if NET10_0_OR_GREATER
30+
eventArgs.DestinationPage;
31+
#else
2832
DestinationPageProperty?.GetValue(eventArgs) as Page;
33+
#endif
2934

3035
/// <summary>
31-
/// Reads the (internal) NavigatedFromEventArgs.PreviousPage property via reflection.
32-
/// Note that this will return null if trimming is enabled.
36+
/// Gets the previous page from navigation arguments.
3337
/// </summary>
3438
public static Page? GetPreviousPage(this NavigatedToEventArgs eventArgs) =>
39+
#if NET10_0_OR_GREATER
40+
eventArgs.PreviousPage;
41+
#else
3542
PreviousPageProperty?.GetValue(eventArgs) as Page;
43+
#endif
3644
}

test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ public void Page_NavigatedTo_AddsBreadcrumb()
8888
Assert.Equal(MauiEventsBinder.NavigationType, crumb.Type);
8989
Assert.Equal(MauiEventsBinder.NavigationCategory, crumb.Category);
9090
crumb.Data.Should().Contain($"{nameof(Page)}.Name", "page");
91-
#if !NET10_0
92-
// TODO: Work out why these are missing in .NET 10
9391
crumb.Data.Should().Contain("PreviousPage", nameof(Page));
9492
crumb.Data.Should().Contain("PreviousPage.Name", "otherPage");
95-
#endif
9693
}
9794

9895
[Fact]

0 commit comments

Comments
 (0)