Sixel.psm1
|
using namespace System.IO using namespace System.Management.Automation using namespace System.Reflection $importModule = Get-Command -Name Import-Module -Module Microsoft.PowerShell.Core $moduleName = [Path]::GetFileNameWithoutExtension($PSCommandPath) $isReload = $true if ($IsCoreClr) { if (-not ('Sixel.Shared.LoadContext' -as [type])) { $isReload = $false Add-Type -Path ([Path]::Combine($PSScriptRoot, 'lib', 'net8.0', "$moduleName.Shared.dll")) } $mainModule = [Sixel.Shared.LoadContext]::Initialize() $innerMod = &$importModule -Assembly $mainModule -PassThru } else { # PowerShell 5.1 has no concept of an Assembly Load Context so it will # just load the module assembly directly. $innerMod = if ('Sixel.Protocols.Sixel' -as [type]) { $modAssembly = [Sixel.Protocols.Sixel].Assembly &$importModule -Assembly $modAssembly -Force -PassThru } else { $isReload = $false $modPath = [Path]::Combine($PSScriptRoot, 'lib', 'net472', "$moduleName.dll") &$importModule -Name $modPath -ErrorAction Stop -PassThru } } if ($isReload) { # https://github.com/PowerShell/PowerShell/issues/20710 $addExportedCmdlet = [PSModuleInfo].GetMethod( 'AddExportedCmdlet', [BindingFlags]'Instance, NonPublic' ) $addExportedAlias = [PSModuleInfo].GetMethod( 'AddExportedAlias', [BindingFlags]'Instance, NonPublic' ) foreach ($cmd in $innerMod.ExportedCmdlets.Values) { $addExportedCmdlet.Invoke($ExecutionContext.SessionState.Module, @(, $cmd)) } foreach ($alias in $innerMod.ExportedAliases.Values) { $addExportedAlias.Invoke($ExecutionContext.SessionState.Module, @(, $alias)) } } |