Skip to content

Support "-is" assignment syntax #9

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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