mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Management.Automation;
|
|
using System.Reflection;
|
|
|
|
namespace Microsoft.PowerShell.PSReadLine
|
|
{
|
|
public class OnModuleImportAndRemove : IModuleAssemblyInitializer, IModuleAssemblyCleanup
|
|
{
|
|
public void OnImport()
|
|
{
|
|
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
|
|
}
|
|
|
|
public void OnRemove(PSModuleInfo module)
|
|
{
|
|
AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load the correct 'Polyfiller' assembly based on the runtime.
|
|
/// </summary>
|
|
private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
|
|
{
|
|
if (args.Name != "Microsoft.PowerShell.PSReadLine.Polyfiller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
|
|
{
|
|
return null;
|
|
}
|
|
|
|
string root = Path.GetDirectoryName(typeof(OnModuleImportAndRemove).Assembly.Location);
|
|
string subd = (Environment.Version.Major >= 6) ? "net6plus" : "net462";
|
|
string path = Path.Combine(root, subd, "Microsoft.PowerShell.PSReadLine.Polyfiller.dll");
|
|
|
|
return Assembly.LoadFrom(path);
|
|
}
|
|
}
|
|
}
|