|
| 1 | +using Sentry.Internal; |
| 2 | + |
1 | 3 | namespace Sentry.Maui.Internal; |
2 | 4 |
|
3 | 5 | internal static class PageNavigationExtensions |
4 | 6 | { |
5 | | - private static readonly PropertyInfo? DestinationPageProperty = |
6 | | - typeof(NavigatedFromEventArgs).GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); |
| 7 | + private static readonly PropertyInfo? DestinationPageProperty; |
| 8 | + private static readonly PropertyInfo? PreviousPageProperty; |
| 9 | + |
| 10 | + [UnconditionalSuppressMessage("Trimming", "IL2075: DynamicallyAccessedMembers", Justification = AotHelper.AvoidAtRuntime)] |
| 11 | + static PageNavigationExtensions() |
| 12 | + { |
| 13 | + if (AotHelper.IsTrimmed) |
| 14 | + { |
| 15 | + return; |
| 16 | + } |
7 | 17 |
|
8 | | - private static readonly PropertyInfo? PreviousPageProperty = |
9 | | - typeof(NavigatedToEventArgs).GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); |
| 18 | + var eventArgsType = typeof(NavigatedFromEventArgs); |
| 19 | + DestinationPageProperty = |
| 20 | + eventArgsType.GetProperty("DestinationPage", BindingFlags.Instance | BindingFlags.NonPublic); |
| 21 | + PreviousPageProperty = |
| 22 | + eventArgsType.GetProperty("PreviousPage", BindingFlags.Instance | BindingFlags.NonPublic); |
| 23 | + } |
10 | 24 |
|
| 25 | + /// <summary> |
| 26 | + /// Reads the (internal) NavigatedFromEventArgs.DestinationPage property via reflection. |
| 27 | + /// Note that this will return null if trimming is enabled. |
| 28 | + /// </summary> |
11 | 29 | public static Page? GetDestinationPage(this NavigatedFromEventArgs eventArgs) => |
12 | 30 | DestinationPageProperty?.GetValue(eventArgs) as Page; |
13 | 31 |
|
| 32 | + /// <summary> |
| 33 | + /// Reads the (internal) NavigatedFromEventArgs.PreviousPage property via reflection. |
| 34 | + /// Note that this will return null if trimming is enabled. |
| 35 | + /// </summary> |
14 | 36 | public static Page? GetPreviousPage(this NavigatedToEventArgs eventArgs) => |
15 | 37 | PreviousPageProperty?.GetValue(eventArgs) as Page; |
16 | 38 | } |
0 commit comments