Add an operator to allow safe checking for property names in Strict Mode #15338
Labels
Issue-Enhancement
the issue is more of a feature request than a bug
Resolution-No Activity
Issue has had no activity for 6 months or more
WG-Language
parser, language semantics
Summary of the new feature/enhancement
Currently Strict Mode is very difficult to use effectively, as there isn't really a good way to safeguard code against errors that may arise from objects not having certain properties. Given how mutable objects can be in powershell, this makes working in strict mode more frustrating than it needs to be.
Proposed technical implementation details (optional)
Currently the only real way to check this is with the somewhat obscure
$object.PSObject.Properties.Name -contains $propName
-- an operator should be provided that checks whether the property exists in a similar way (can we be more thorough than this? Should we?) and safely returns a null or false so that these expressions are easier to write.Temporarily borrowing the
?.
operator for now (we don't have to use this operator, but at least to me it sort of makes sense here), it would look something like this:The text was updated successfully, but these errors were encountered: