Skip to content

Use null propagation operator for windows build#17795

Merged
PaulHigin merged 7 commits intoPowerShell:masterfrom
fflaten:fix-nullprop-win
Jul 29, 2022
Merged

Use null propagation operator for windows build#17795
PaulHigin merged 7 commits intoPowerShell:masterfrom
fflaten:fix-nullprop-win

Conversation

@fflaten
Copy link
Copy Markdown
Contributor

@fflaten fflaten commented Jul 28, 2022

PR Summary

Replace if not null-checks with null propagation operator to solve IDE0031 with .NET Preview 7.
Additional findings when compiled against win7-x64 (in devcontainer).

PR Context

Related to #17769

PR Checklist

@fflaten
Copy link
Copy Markdown
Contributor Author

fflaten commented Jul 28, 2022

Don't have a Windows-machine to build on atm. but hopefully I caught most of them.

@iSazonov Any tips regarding 31408eb ?
When building in devcontainer with -Runtime win7-x64 and changing them to securityDescHandle?.Value.Free(); it failed with:

/workspaces/PowerShell/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs(2850,32): error CS1061: 'GCHandle' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'GCHandle' could be found (are you missing a using directive or an assembly reference?) [/workspaces/PowerShell/src/System.Management.Automation/System.Management.Automation.csproj]
/workspaces/PowerShell/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs(507,32): error CS1061: 'GCHandle' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'GCHandle' could be found (are you missing a using directive or an assembly reference?) [/workspaces/PowerShell/src/System.Management.Automation/System.Management.Automation.csproj]

Update: Never mind. ?. removes nullable from the type.

Comment thread src/Microsoft.WSMan.Management/WsManHelper.cs Outdated
Comment thread src/Microsoft.WSMan.Management/WsManHelper.cs Outdated
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 28, 2022
Comment thread src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs Outdated
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 28, 2022
Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
securityDescHandle.Value.Free();
}
securityDescHandle?.Free();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It generates more efficient code. I wonder but it is great!
Compere:
before
after

@PaulHigin PaulHigin merged commit 5f4e100 into PowerShell:master Jul 29, 2022
@fflaten fflaten deleted the fix-nullprop-win branch July 29, 2022 17:54
@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Jul 31, 2022
@fflaten fflaten mentioned this pull request Aug 1, 2022
22 tasks
@ghost
Copy link
Copy Markdown

ghost commented Aug 11, 2022

🎉v7.3.0-preview.7 has been released which incorporates this pull request.:tada:

Handy links:

@TravisEz13 TravisEz13 mentioned this pull request Sep 30, 2022
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants