-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
NETEnvironmentInfo.cs
83 lines (67 loc) · 2.9 KB
/
NETEnvironmentInfo.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
78
79
80
81
82
83
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Deployment.DotNet.Releases;
using static Microsoft.DotNet.NativeWrapper.Interop;
namespace Microsoft.DotNet.NativeWrapper
{
public interface INetBundleInfo
{
public ReleaseVersion Version { get; }
public string Path { get; }
}
public sealed class NetSdkInfo : INetBundleInfo
{
public ReleaseVersion Version { get; private set; }
public string Path { get; private set; }
public NetSdkInfo(string version, string path)
{
Version = new ReleaseVersion(version);
Path = path;
}
}
public sealed class NetRuntimeInfo : INetBundleInfo
{
public ReleaseVersion Version { get; private set; }
public string Path { get; private set; }
public string Name { get; private set; }
public NetRuntimeInfo(string name, string version, string path)
{
Version = new ReleaseVersion(version);
Path = path;
Name = name;
}
}
public sealed class NetEnvironmentInfo
{
public IEnumerable<NetRuntimeInfo> RuntimeInfo { get; private set; }
public IEnumerable<NetSdkInfo> SdkInfo { get; private set; }
public NetEnvironmentInfo(IEnumerable<NetRuntimeInfo> runtimeInfo, IEnumerable<NetSdkInfo> sdkInfo)
{
RuntimeInfo = runtimeInfo;
SdkInfo = sdkInfo;
}
public NetEnvironmentInfo()
{
RuntimeInfo = new List<NetRuntimeInfo>();
SdkInfo = new List<NetSdkInfo>();
}
internal void Initialize(IntPtr info, IntPtr resultContext)
{
var infoStruct = Marshal.PtrToStructure<hostfxr_dotnet_environment_info>(info);
var runtimes = new hostfxr_dotnet_environment_framework_info[infoStruct.framework_count];
for (var i = 0; i < (int)infoStruct.framework_count; i++)
{
var pointer = new IntPtr(infoStruct.frameworks.ToInt64() + i * Marshal.SizeOf(typeof(hostfxr_dotnet_environment_framework_info)));
runtimes[i] = Marshal.PtrToStructure<hostfxr_dotnet_environment_framework_info>(pointer);
}
RuntimeInfo = runtimes.Select(runtime => new NetRuntimeInfo(runtime.name, runtime.version, runtime.path));
var sdks = new hostfxr_dotnet_environment_sdk_info[infoStruct.sdk_count];
for (var i = 0; i < (int)infoStruct.sdk_count; i++)
{
var pointer = new IntPtr(infoStruct.sdks.ToInt64() + i * Marshal.SizeOf(typeof(hostfxr_dotnet_environment_sdk_info)));
sdks[i] = Marshal.PtrToStructure<hostfxr_dotnet_environment_sdk_info>(pointer);
}
SdkInfo = sdks.Select(sdk => new NetSdkInfo(sdk.version, sdk.path));
}
}
}