Enable type conversion when passing properties#297
Merged
devblackops merged 1 commit intomasterfrom Apr 13, 2020
Merged
Conversation
Set-Item does not perform type conversion, but Set-Variable does.
For example with such properties:
```powershell
properties {
[uri]$applicationUrl = $null
}
```
Without this change passing the URL like this:
```shell
psake -properties @{ applicationUrl = "http://app.example.com" }
```
Will make the $applicationUrl variable to be of type [string] instead of [uri]. This is unexpected, as normally variable defined with type accelerator will automatically convert other types to the specified type, for example
```powershell
[uri]$myUrl = "http://my.example.com"
$myUrl = "http://other.example.com" # this still is [uri], not a [string]
```
Set-Variable preserve behavior of variables defined with type accelerators, while Set-Item sadly does not:).
BTW. there is a workaround: you can pass the type info again when passing parameter in psake, but this is error prone, as this is not needed normally in PowerShell, only in psake: `psake -properties @{ applicationUrl = [uri]"http://app.example.com" }`
Member
|
This is a good fix @whut. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set-Item does not perform type conversion, but Set-Variable does.
For example with such properties:
properties { [uri]$applicationUrl = $null }Without this change passing the URL like this:
psake -properties @{ applicationUrl = "http://app.example.com" }Will make the $applicationUrl variable to be of type [string] instead of [uri]. This is unexpected, as normally variable defined with type accelerator will automatically convert other types to the specified type, for example
Set-Variable preserve behavior of variables defined with type accelerators, while Set-Item sadly does not:).
BTW. there is a workaround: you can pass the type info again when passing parameter in psake, but this is error prone, as this is not needed normally in PowerShell, only in psake:
psake -properties @{ applicationUrl = [uri]"http://app.example.com" }Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: