PSLambda icon indicating copy to clipboard operation
PSLambda copied to clipboard

Support "-is" assignment syntax

Open SeeminglyScience opened this issue 7 years ago • 0 comments

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()
}

SeeminglyScience avatar Apr 24 '18 15:04 SeeminglyScience