ScriptBlock
をDelegate
に変換しようとするとlambda_method
になる様子
$lambdaMethod = [System.IO.FileSystemEventHandler]([ScriptBlock]::Create(""))
$lambdaMethod | Format-List
引数の確認
$lambdaMethod = [System.IO.FileSystemEventHandler]{}
$lambdaMethod | Get-Member -Name Invoke
$args
の確認
$lambdaMethod = [System.IO.FileSystemEventHandler]{
Get-Variable -Scope Local -Name args | Out-String | Write-Host
}
$lambdaMethod.Invoke($null, $null)
引数の確認
([System.Func[string, string, string]]{}).Invoke
param
を使う場合の確認
([System.Func[string, string, string]]{
param ([string]$arg1, [string]$arg2)
$arg1 + $arg2 | Write-Host
Get-Variable -Scope Local | Out-String -Width 80 | Write-Verbose -Verbose
}).Invoke("abc", "def")
List<T>.Sort(Comparison<T>)
の確認
Add-Type -Language CSharp -TypeDefinition @'
using System.Runtime.InteropServices;
namespace Win32API {
public class Shlwapi {
[DllImport("Shlwapi.dll", EntryPoint = "StrCmpLogicalW", CharSet = CharSet.Unicode)]
public static extern int StrCmpLogicalW(
[MarshalAs(UnmanagedType.LPWStr)] string psz1,
[MarshalAs(UnmanagedType.LPWStr)] string psz2
);
}
}
'@
$psObjList = [System.Collections.Generic.List[PSObject]][PSObject[]]@(Get-ChildItem)
$psObjList | Select-Object -Property Name | ForEach-Object { Write-Host $_.Name -ForegroundColor Green }
$cmp = [System.Comparison[PSObject]]{
param ([PSObject]$x, [PSObject]$y)
return [Win32API.Shlwapi]::StrCmpLogicalW($x.Name, $y.Name)
}
$psObjList.Sort($cmp)
$psObjList | Select-Object -Property Name | ForEach-Object { Write-Host $_.Name -ForegroundColor Cyan }