better null comparison (#10915)

This commit is contained in:
William Cheng 2021-11-21 23:03:25 +08:00 committed by GitHub
parent 37a4429024
commit c244c23053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 13 deletions

View File

@ -144,7 +144,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
{{/hasHttpSignatureMethods}} {{/hasHttpSignatureMethods}}
if ($SkipCertificateCheck -eq $true) { if ($SkipCertificateCheck -eq $true) {
if ($Configuration["Proxy"] -eq $null) { if ($null -eq $Configuration["Proxy"]) {
# skip certification check, no proxy # skip certification check, no proxy
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` $Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method ` -Method $Method `
@ -166,7 +166,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
-ProxyUseDefaultCredentials -ProxyUseDefaultCredentials
} }
} else { } else {
if ($Configuration["Proxy"] -eq $null) { if ($null -eq $Configuration["Proxy"]) {
# perform certification check, no proxy # perform certification check, no proxy
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` $Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method ` -Method $Method `
@ -241,7 +241,7 @@ function DeserializeResponse {
[string[]]$ContentTypes [string[]]$ContentTypes
) )
If ($ContentTypes -eq $null) { If ($null -eq $ContentTypes) {
$ContentTypes = [string[]]@() $ContentTypes = [string[]]@()
} }

View File

@ -20,7 +20,7 @@ test_script:
} }
deploy_script: deploy_script:
- pwsh: | - pwsh: |
if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null) { if ($env:APPVEYOR_REPO_TAG -eq $true -and $null -ne $env:NuGetApiKey) {
.\Build.ps1 .\Build.ps1
try { try {
Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\{{{packageName}}}\ -Confirm:$False -Verbose Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\{{{packageName}}}\ -Confirm:$False -Verbose

View File

@ -172,7 +172,7 @@ function Set-{{{apiNamePrefix}}}Configuration {
$Script:Configuration['DefaultHeaders'] = $DefaultHeaders $Script:Configuration['DefaultHeaders'] = $DefaultHeaders
} }
If ($Proxy -ne $null) { If ($null -ne $Proxy) {
If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") { If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") {
throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque." throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque."
} }

View File

@ -73,7 +73,7 @@ function Initialize-{{{apiNamePrefix}}}{{{classname}}} {
{{#vars}} {{#vars}}
{{^isNullable}} {{^isNullable}}
{{#required}} {{#required}}
if (${{{name}}} -eq $null) { if ($null -eq ${{{name}}}) {
throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null." throw "invalid value for '{{{name}}}', '{{{name}}}' cannot be null."
} }

View File

@ -26,7 +26,7 @@ test_script:
} }
deploy_script: deploy_script:
- pwsh: | - pwsh: |
if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null) { if ($env:APPVEYOR_REPO_TAG -eq $true -and $null -ne $env:NuGetApiKey) {
.\Build.ps1 .\Build.ps1
try { try {
Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\PSPetstore\ -Confirm:$False -Verbose Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\src\PSPetstore\ -Confirm:$False -Verbose

View File

@ -178,7 +178,7 @@ function Set-PSConfiguration {
$Script:Configuration['DefaultHeaders'] = $DefaultHeaders $Script:Configuration['DefaultHeaders'] = $DefaultHeaders
} }
If ($Proxy -ne $null) { If ($null -ne $Proxy) {
If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") { If ($Proxy.GetType().FullName -ne "System.Net.SystemWebProxy" -and $Proxy.GetType().FullName -ne "System.Net.WebRequest+WebProxyWrapperOpaque") {
throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque." throw "Incorrect Proxy type '$($Proxy.GetType().FullName)'. Must be System.Net.SystemWebProxy or System.Net.WebRequest+WebProxyWrapperOpaque."
} }

View File

@ -59,11 +59,11 @@ function Initialize-PSPet {
'Creating PSCustomObject: PSPetstore => PSPet' | Write-Debug 'Creating PSCustomObject: PSPetstore => PSPet' | Write-Debug
$PSBoundParameters | Out-DebugParameter | Write-Debug $PSBoundParameters | Out-DebugParameter | Write-Debug
if ($Name -eq $null) { if ($null -eq $Name) {
throw "invalid value for 'Name', 'Name' cannot be null." throw "invalid value for 'Name', 'Name' cannot be null."
} }
if ($PhotoUrls -eq $null) { if ($null -eq $PhotoUrls) {
throw "invalid value for 'PhotoUrls', 'PhotoUrls' cannot be null." throw "invalid value for 'PhotoUrls', 'PhotoUrls' cannot be null."
} }

View File

@ -131,7 +131,7 @@ function Invoke-PSApiClient {
} }
if ($SkipCertificateCheck -eq $true) { if ($SkipCertificateCheck -eq $true) {
if ($Configuration["Proxy"] -eq $null) { if ($null -eq $Configuration["Proxy"]) {
# skip certification check, no proxy # skip certification check, no proxy
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` $Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method ` -Method $Method `
@ -153,7 +153,7 @@ function Invoke-PSApiClient {
-ProxyUseDefaultCredentials -ProxyUseDefaultCredentials
} }
} else { } else {
if ($Configuration["Proxy"] -eq $null) { if ($null -eq $Configuration["Proxy"]) {
# perform certification check, no proxy # perform certification check, no proxy
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri ` $Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method ` -Method $Method `
@ -228,7 +228,7 @@ function DeserializeResponse {
[string[]]$ContentTypes [string[]]$ContentTypes
) )
If ($ContentTypes -eq $null) { If ($null -eq $ContentTypes) {
$ContentTypes = [string[]]@() $ContentTypes = [string[]]@()
} }