Skip to content

Allow $null on right-hand side of -is and -isnot operators. #10656

Description

@KirkMunro

Summary of the new feature/enhancement

As a scripter,
I want to use -is and -isnot when comparing a value against $null instead of -eq and -ne
so that the comparison always works, even with collections or with types that overload the equality operator.

For reference: https://youtu.be/TJiLhRPgyq4?list=PLReL099Y5nRd04p81Q7p5TtyjCrj9tz1t&t=373

Proposed technical implementation details (optional)

Update the implementation of the -is and -isnot operators such that they allow $null in addition to types on the right operand, and when comparing against null they simply use the C# is operator internally to perform the comparison (which they may do already, so this may be a very trivial change to make.

This change makes for a much more expressive syntax as well, which reads very well in PowerShell.

Here is what I want to work once this is implemented:

$x -is $null
$y -isnot $null
$collection | where Property -is $null
$collection | where Property -isnot $null

I plan on implementing this PR as part of Hacktoberfest.

Activity

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

Metadata

Metadata

Labels

Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions