-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Trim warnings in DiagnosticSource and WinUIUnhandledException i…
…ntegrations (#3410)
- Loading branch information
1 parent
3cc2e44
commit 9f36d22
Showing
12 changed files
with
106 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Sentry.DiagnosticSource/Internal/DiagnosticSource/ReflectionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Sentry.Extensibility; | ||
|
||
namespace Sentry.Internal.DiagnosticSource; | ||
|
||
/// <summary> | ||
/// Various reflection helper methods. | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that the methods in this class are incompatible with Trimming. They are | ||
/// used exclusively in the `Sentry.Internal.DiagnosticSource` integration, which | ||
/// we disable if trimming is enabled to avoid problems at runtime. | ||
/// </remarks> | ||
internal static class ReflectionHelper | ||
{ | ||
[UnconditionalSuppressMessage("TrimAnalyzer", "IL2075", Justification = AotHelper.SuppressionJustification)] | ||
public static object? GetProperty(this object obj, string name, IDiagnosticLogger? logger = null) | ||
{ | ||
if (AotHelper.IsTrimmed) | ||
{ | ||
logger?.LogInfo("ReflectionHelper.GetProperty should not be used when trimming is enabled"); | ||
return null; | ||
} | ||
|
||
var propertyNames = name.Split('.'); | ||
var currentObj = obj; | ||
|
||
foreach (var propertyName in propertyNames) | ||
{ | ||
var property = currentObj?.GetType().GetProperty(propertyName); | ||
if (property == null) | ||
{ | ||
return null; | ||
} | ||
|
||
currentObj = property.GetValue(currentObj); | ||
} | ||
|
||
return currentObj; | ||
} | ||
|
||
public static Guid? GetGuidProperty(this object obj, string name, IDiagnosticLogger? logger = null) => | ||
obj.GetProperty(name, logger) as Guid?; | ||
|
||
public static string? GetStringProperty(this object obj, string name, IDiagnosticLogger? logger = null) => | ||
obj.GetProperty(name, logger) as string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...ternals/Extensions/MiscExtensionsTests.cs → ...sticSource.Tests/ReflectionHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters