-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathSentryNative.cs
32 lines (26 loc) · 1.1 KB
/
SentryNative.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Sentry.Internal;
using Sentry.PlatformAbstractions;
// ReSharper disable once CheckNamespace
namespace Sentry;
internal static class SentryNative
{
#if NET8_0_OR_GREATER
// Should be in-sync with Sentry.Native.targets const.
private const string SentryNativeIsEnabledSwitchName = "Sentry.Native.IsEnabled";
private static readonly bool IsAvailableCore;
#if NET9_0_OR_GREATER
// FeatureSwitchDefinition should help with trimming disabled code.
// This way, `Sentry.Native.IsEnabled` should be treated as a compile-time constant for trimmed apps.
[FeatureSwitchDefinition(SentryNativeIsEnabledSwitchName)]
#endif
private static bool IsEnabled => !AppContext.TryGetSwitch(SentryNativeIsEnabledSwitchName, out var isEnabled) || isEnabled;
internal static bool IsAvailable => IsEnabled && IsAvailableCore;
static SentryNative()
{
IsAvailableCore = AotHelper.IsTrimmed && !SentryRuntime.Current.IsBrowserWasm();
}
#else
// This is a compile-time const so that the irrelevant code is removed during compilation.
internal const bool IsAvailable = false;
#endif
}