-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
RuntimeAssembly.cs
47 lines (40 loc) · 1.46 KB
/
RuntimeAssembly.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Reflection;
namespace Microsoft.Extensions.DependencyModel
{
public class RuntimeAssembly
{
private const string NativeImageSufix = ".ni";
private readonly string _assemblyName;
public RuntimeAssembly(string assemblyName, string path)
{
if (string.IsNullOrEmpty(assemblyName))
{
throw new ArgumentException(null, nameof(assemblyName));
}
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException(null, nameof(path));
}
_assemblyName = assemblyName;
Path = path;
}
public AssemblyName Name => new(_assemblyName);
public string Path { get; }
public static RuntimeAssembly Create(string path)
{
string assemblyName = System.IO.Path.GetFileNameWithoutExtension(path);
if (assemblyName == null)
{
throw new ArgumentException($"Provided path has empty file name '{path}'", nameof(path));
}
if (assemblyName.EndsWith(NativeImageSufix))
{
assemblyName = assemblyName.Substring(0, assemblyName.Length - NativeImageSufix.Length);
}
return new RuntimeAssembly(assemblyName, path);
}
}
}