Skip to content

Support "-is" assignment syntax #9

@SeeminglyScience

Description

@SeeminglyScience

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions