/
CoreRtRuntime.cs
46 lines (40 loc) · 1.71 KB
/
CoreRtRuntime.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
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using System;
namespace BenchmarkDotNet.Environments
{
public class CoreRtRuntime : Runtime
{
/// <summary>
/// CoreRT compiled as net5.0
/// </summary>
public static readonly CoreRtRuntime CoreRt50 = new CoreRtRuntime(RuntimeMoniker.CoreRt50, "net5.0", "CoreRT 5.0");
/// <summary>
/// CoreRT compiled as net6.0
/// </summary>
public static readonly CoreRtRuntime CoreRt60 = new CoreRtRuntime(RuntimeMoniker.CoreRt60, "net6.0", "CoreRT 6.0");
public override bool IsAOT => true;
private CoreRtRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName)
: base(runtimeMoniker, msBuildMoniker, displayName)
{
}
public static CoreRtRuntime GetCurrentVersion()
{
if (!RuntimeInformation.IsNetCore && !RuntimeInformation.IsCoreRT)
{
throw new NotSupportedException("It's impossible to reliably detect the version of CoreRT if the process is not a .NET Core or CoreRT process!");
}
if (!CoreRuntime.TryGetVersion(out var version))
{
throw new NotSupportedException("Failed to recognize CoreRT version");
}
switch (version)
{
case Version v when v.Major == 5 && v.Minor == 0: return CoreRt50;
case Version v when v.Major == 6 && v.Minor == 0: return CoreRt60;
default:
return new CoreRtRuntime(RuntimeMoniker.NotRecognized, $"net{version.Major}.{version.Minor}", $"CoreRT {version.Major}.{version.Minor}");
}
}
}
}