AST ‘splatting’ with static methods.

PowerShell-Splatting-With-StaticHave you ever wanted to use splatting outside it’s normal use with PowerShell commands? Splatting is great to pass (named) parameters to commands, but there are other elements that have named parameters. Perfect example: static methods that exist on .NET types. Unfortunately, in current version of PowerShell we can’t extend splatting concept to other language elements. But I guess a lot of people would agree with me: it would be great to be able to do something like:

$ToSplat = @{            
    format = "Using 'splatting' hashtable: {0:N2} and {1:N3}"            
    args = [math]::PI, [math]::E            
}            
            
[string]::Format(@ToSplat)

It may happen one day, but can we do anything about it now? Well… sure!

Continue reading