/
Platform.cs
77 lines (72 loc) · 2.94 KB
/
Platform.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace Stride.Core
{
/// <summary>
/// Platform specific queries and functions.
/// </summary>
public static class Platform
{
#if STRIDE_PLATFORM_WINDOWS_DESKTOP
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.Windows;
#elif STRIDE_PLATFORM_UWP
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.UWP;
#elif STRIDE_PLATFORM_ANDROID
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.Android;
#elif STRIDE_PLATFORM_IOS
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.iOS;
#elif STRIDE_PLATFORM_MACOS
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.macOS;
#elif STRIDE_PLATFORM_LINUX
/// <summary>
/// The current running <see cref="PlatformType"/>.
/// </summary>
public static readonly PlatformType Type = PlatformType.Linux;
#endif
/// <summary>
/// Gets a value indicating whether the running platform is windows desktop.
/// </summary>
/// <value><c>true</c> if this instance is windows desktop; otherwise, <c>false</c>.</value>
public static readonly bool IsWindowsDesktop = Type == PlatformType.Windows;
/// <summary>
/// Gets a value indicating whether the running assembly is a debug assembly.
/// </summary>
public static readonly bool IsRunningDebugAssembly = GetIsRunningDebugAssembly();
/// <summary>
/// Check if running assembly has the DebuggableAttribute set with the `DisableOptimizations` mode enabled.
/// This function is called only once.
/// </summary>
private static bool GetIsRunningDebugAssembly()
{
var entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly != null)
{
var debuggableAttribute = entryAssembly.GetCustomAttributes<DebuggableAttribute>().FirstOrDefault();
if (debuggableAttribute != null)
{
return (debuggableAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.DisableOptimizations) != 0;
}
}
return false;
}
}
}