Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/Sentry.Maui/Internal/PageNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,22 +16,29 @@ static PageNavigationExtensions()
return;
}
DestinationPageProperty = typeof(NavigatedFromEventArgs)
.GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic);
.GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.Public);
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
PreviousPageProperty = typeof(NavigatedToEventArgs)
.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic);
.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.Public);
Comment thread
sentry[bot] marked this conversation as resolved.
Outdated
}
#endif

/// <summary>
/// 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.
/// </summary>
public static Page? GetDestinationPage(this NavigatedFromEventArgs eventArgs) =>
#if NET10_0_OR_GREATER
eventArgs.DestinationPage;
#else
DestinationPageProperty?.GetValue(eventArgs) as Page;
#endif

/// <summary>
/// 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.
/// </summary>
public static Page? GetPreviousPage(this NavigatedToEventArgs eventArgs) =>
#if NET10_0_OR_GREATER
eventArgs.PreviousPage;
#else
PreviousPageProperty?.GetValue(eventArgs) as Page;
#endif
}
2 changes: 0 additions & 2 deletions test/Sentry.Maui.Tests/MauiEventsBinderTests.Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ 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]
Expand Down