PSLambda
PSLambda copied to clipboard
Support "-is" assignment syntax
Casting and -as are both funneled through LanguagePrimitives.ConvertTo or LanguagePrimitives.TryConvertTo. These can produce some unexpected results when expecting a more static typing system. Right now the -is and -isnot operators are strict and do not actually change the object. I'd like to support the assignment syntax that C# has.
object item = someValue;
if (item is System.IO.FileSystemInfo info)
{
info.Delete();
}
This should be pretty easy since the following syntax does not produce any parse errors from the PowerShell engine. And currently this will produce a compiler error due to the rhs not being a type constant
if ($item -is [System.IO.FileSystemInfo] $info) {
$info.Delete()
}