-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEndiannessCheck.cs
More file actions
30 lines (29 loc) · 1.17 KB
/
EndiannessCheck.cs
File metadata and controls
30 lines (29 loc) · 1.17 KB
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
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Stardust.Utilities
{
internal static class EndiannessCheck
{
/// <summary>
/// Ensures the assembly is loaded on an architecture matching its compilation target.
/// </summary>
[ModuleInitializer]
[SuppressMessage("Performance", "CA2255:The 'ModuleInitializer' attribute should not be used in libraries",
Justification = "Required for platform compatibility check - must fail fast before any library code executes.")]
internal static void EnsureCorrectEndianness()
{
#if BIG_ENDIAN
if (BitConverter.IsLittleEndian)
{
throw new PlatformNotSupportedException("The Stardust.Utilities library was compiled for Big-Endian architectures but is running on a Little-Endian architecture.");
}
#else
if (!BitConverter.IsLittleEndian)
{
throw new PlatformNotSupportedException("The Stardust.Utilities library was compiled for Little-Endian architectures but is running on a Big-Endian architecture.");
}
#endif
}
}
}