diff --git a/eng/Version.Details.props b/eng/Version.Details.props index aa1fc141196..7f774b1633e 100644 --- a/eng/Version.Details.props +++ b/eng/Version.Details.props @@ -1 +1,65 @@ - + + + + + + 10.0.0-beta.25409.103 + 10.0.0-beta.25409.103 + 10.0.0-beta.25409.103 + 10.0.0-beta.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 8.0.0-beta.23409.2 + 8.0.0-beta.23409.2 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + 10.0.0-rc.1.25409.103 + + 10.0.0-preview.7.25317.2 + + + + + $(MicrosoftDotNetArcadeSdkPackageVersion) + $(MicrosoftDotNetCodeAnalysisPackageVersion) + $(MicrosoftDotNetGenAPIPackageVersion) + $(MicrosoftDotNetHelixSdkPackageVersion) + $(MicrosoftDotnetWinFormsProjectTemplatesPackageVersion) + $(MicrosoftNETCoreAppRefPackageVersion) + $(MicrosoftNETCorePlatformsPackageVersion) + $(MicrosoftPrivateWinformsPackageVersion) + $(MicrosoftSourceLinkAzureReposGitPackageVersion) + $(MicrosoftSourceLinkGitHubPackageVersion) + $(SystemCodeDomPackageVersion) + $(SystemConfigurationConfigurationManagerPackageVersion) + $(SystemDiagnosticsEventLogPackageVersion) + $(SystemDirectoryServicesPackageVersion) + $(SystemDrawingCommonPackageVersion) + $(SystemFormatsNrbfPackageVersion) + $(SystemIOPackagingPackageVersion) + $(SystemReflectionMetadataLoadContextPackageVersion) + $(SystemResourcesExtensionsPackageVersion) + $(SystemRuntimeSerializationFormattersPackageVersion) + $(SystemSecurityCryptographyXmlPackageVersion) + $(SystemSecurityPermissionsPackageVersion) + $(SystemWindowsExtensionsPackageVersion) + + $(MicrosoftDotNetWpfDncEngPackageVersion) + + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 50edc5663c5..ad98380ec89 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,104 +1,105 @@ - + - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c https://dev.azure.com/dnceng/internal/_git/dotnet-wpf-int 8a6c1d81657ef04c040f598cafacf8f5a33abda2 - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c - + https://github.com/dotnet/dotnet - 6a953e76162f3f079405f80e28664fa51b136740 + e9f665e52848a3615736c099e5631af531b66a5c diff --git a/eng/Versions.props b/eng/Versions.props index bcc18a610a7..e030560d18c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,5 +1,6 @@ + 10 0 @@ -18,33 +19,10 @@ dotnet/winforms is handling versions for the analyzers. --> $(MajorVersion).$(MinorVersion).0.0 - 10.0.0-beta.25377.103 - 10.0.0-beta.25377.103 - 10.0.0-beta.25377.103 - - - - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 4.6.0-preview4.19176.11 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 - 10.0.0-preview.7.25377.103 @@ -58,12 +36,6 @@ 9.0.0-beta.24053.1 - 10.0.0-beta.25377.103 - - - - 8.0.0-beta.23409.2 - 8.0.0-beta.23409.2 @@ -131,7 +103,4 @@ System.IO.Packaging System.Reflection.MetadataLoadContext - - 10.0.0-preview.7.25317.2 - diff --git a/eng/common/core-templates/job/onelocbuild.yml b/eng/common/core-templates/job/onelocbuild.yml index 8034815f421..8bf7d23355b 100644 --- a/eng/common/core-templates/job/onelocbuild.yml +++ b/eng/common/core-templates/job/onelocbuild.yml @@ -4,7 +4,7 @@ parameters: # Optional: A defined YAML pool - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pool pool: '' - + CeapexPat: $(dn-bot-ceapex-package-r) # PAT for the loc AzDO instance https://dev.azure.com/ceapex GithubPat: $(BotAccount-dotnet-bot-repo-PAT) @@ -27,7 +27,7 @@ parameters: is1ESPipeline: '' jobs: - job: OneLocBuild${{ parameters.JobNameSuffix }} - + dependsOn: ${{ parameters.dependsOn }} displayName: OneLocBuild${{ parameters.JobNameSuffix }} @@ -99,22 +99,20 @@ jobs: mirrorBranch: ${{ parameters.MirrorBranch }} condition: ${{ parameters.condition }} - - template: /eng/common/core-templates/steps/publish-build-artifacts.yml - parameters: - is1ESPipeline: ${{ parameters.is1ESPipeline }} - args: - displayName: Publish Localization Files - pathToPublish: '$(Build.ArtifactStagingDirectory)/loc' - publishLocation: Container - artifactName: Loc - condition: ${{ parameters.condition }} + # Copy the locProject.json to the root of the Loc directory, then publish a pipeline artifact + - task: CopyFiles@2 + displayName: Copy LocProject.json + inputs: + SourceFolder: '$(Build.SourcesDirectory)/eng/Localize/' + Contents: 'LocProject.json' + TargetFolder: '$(Build.ArtifactStagingDirectory)/loc' + condition: ${{ parameters.condition }} - - template: /eng/common/core-templates/steps/publish-build-artifacts.yml + - template: /eng/common/core-templates/steps/publish-pipeline-artifacts.yml parameters: is1ESPipeline: ${{ parameters.is1ESPipeline }} args: - displayName: Publish LocProject.json - pathToPublish: '$(Build.SourcesDirectory)/eng/Localize/' - publishLocation: Container - artifactName: Loc + targetPath: '$(Build.ArtifactStagingDirectory)/loc' + artifactName: 'Loc' + displayName: 'Publish Localization Files' condition: ${{ parameters.condition }} diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index 996a5f9c872..d4cfd9ccd80 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -257,7 +257,20 @@ function Retry($downloadBlock, $maxRetries = 5) { function GetDotNetInstallScript([string] $dotnetRoot) { $installScript = Join-Path $dotnetRoot 'dotnet-install.ps1' + $shouldDownload = $false + if (!(Test-Path $installScript)) { + $shouldDownload = $true + } else { + # Check if the script is older than 30 days + $fileAge = (Get-Date) - (Get-Item $installScript).LastWriteTime + if ($fileAge.Days -gt 30) { + Write-Host "Existing install script is too old, re-downloading..." + $shouldDownload = $true + } + } + + if ($shouldDownload) { Create-Directory $dotnetRoot $ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit $uri = "https://builds.dotnet.microsoft.com/dotnet/scripts/$dotnetInstallScriptVersion/dotnet-install.ps1" diff --git a/eng/common/tools.sh b/eng/common/tools.sh index 3def02a638d..c1841c9dfd0 100755 --- a/eng/common/tools.sh +++ b/eng/common/tools.sh @@ -300,8 +300,29 @@ function GetDotNetInstallScript { local root=$1 local install_script="$root/dotnet-install.sh" local install_script_url="https://builds.dotnet.microsoft.com/dotnet/scripts/$dotnetInstallScriptVersion/dotnet-install.sh" + local timestamp_file="$root/.dotnet-install.timestamp" + local should_download=false if [[ ! -a "$install_script" ]]; then + should_download=true + elif [[ -f "$timestamp_file" ]]; then + # Check if the script is older than 30 days using timestamp file + local download_time=$(cat "$timestamp_file" 2>/dev/null || echo "0") + local current_time=$(date +%s) + local age_seconds=$((current_time - download_time)) + + # 30 days = 30 * 24 * 60 * 60 = 2592000 seconds + if [[ $age_seconds -gt 2592000 ]]; then + echo "Existing install script is too old, re-downloading..." + should_download=true + fi + else + # No timestamp file exists, assume script is old and re-download + echo "No timestamp found for existing install script, re-downloading..." + should_download=true + fi + + if [[ "$should_download" == true ]]; then mkdir -p "$root" echo "Downloading '$install_script_url'" @@ -328,6 +349,9 @@ function GetDotNetInstallScript { ExitWithExitCode $exit_code } fi + + # Create timestamp file to track download time in seconds from epoch + date +%s > "$timestamp_file" fi # return value _GetDotNetInstallScript="$install_script" diff --git a/global.json b/global.json index cd81570e53a..8d934ca0eb9 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.100-preview.7.25322.101", + "version": "10.0.100-preview.7.25372.107", "allowPrerelease": true, "rollForward": "latestFeature", "paths": [ @@ -10,7 +10,7 @@ "errorMessage": "The required .NET SDK wasn't found. Please run ./eng/common/dotnet.cmd/sh to install it." }, "tools": { - "dotnet": "10.0.100-preview.7.25322.101", + "dotnet": "10.0.100-preview.7.25372.107", "runtimes": { "dotnet/x64": [ "$(MicrosoftNETCorePlatformsVersion)" @@ -24,8 +24,8 @@ } }, "msbuild-sdks": { - "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25377.103", - "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25377.103", + "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25409.103", + "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25409.103", "Microsoft.Build.NoTargets": "3.7.56" }, "native-tools": { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs index f21a36da2e9..acec1405f51 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs @@ -550,28 +550,18 @@ private void _Compile(string relativeSourceFile, bool pass2) xamlParser.BamlRecordWriter == null && IsBamlNeeded) { - if (_pendingLocalFiles == null) - { - _pendingLocalFiles = new ArrayList(10); - } + _pendingLocalFiles ??= new ArrayList(10); _pendingLocalFiles.Add(relativeSourceFile); } - if (_codeContexts != null) - { - _codeContexts.Clear(); - _codeContexts = null; - } + _codeContexts?.Clear(); + _codeContexts = null; SourceFileInfo?.CloseStream(); - - if (bamlStream != null) - { - bamlStream.Close(); - bamlStream = null; - } + bamlStream?.Close(); + bamlStream = null; } } @@ -597,11 +587,8 @@ private void GenerateSource() _ccRoot.CodeNS.Types.Add(_ccRoot.CodeClass); } - if (_usingNS != null) - { - _usingNS.Clear(); - _usingNS = null; - } + _usingNS?.Clear(); + _usingNS = null; if (IsCompilingEntryPointClass) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs index bfb0d523857..cacd2dfbefa 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs @@ -676,12 +676,8 @@ public override void WriteEndAttributes(XamlEndAttributesNode xamlEndAttributesN _compiler.ConnectNameAndEvents(_name, _events, _connectionId); _name = null; - - if (_events != null) - { - _events.Clear(); - _events = null; - } + _events?.Clear(); + _events = null; } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Shared/SourceFileInfo.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Shared/SourceFileInfo.cs index 349b79651e4..edd9974e82e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Shared/SourceFileInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Shared/SourceFileInfo.cs @@ -138,11 +138,8 @@ internal Stream Stream // internal void CloseStream() { - if (_stream != null) - { - _stream.Close(); - _stream = null; - } + _stream?.Close(); + _stream = null; } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs index 000695ad454..6f31dc30cfc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs @@ -103,11 +103,8 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (null != _sourceStream) - { - _sourceStream.Dispose(); - _sourceStream = null; - } + _sourceStream?.Dispose(); + _sourceStream = null; } } } @@ -153,7 +150,7 @@ public override bool Execute() return false; } - if (OutputResourcesFile != null && OutputResourcesFile.Length > 1) + if (OutputResourcesFile?.Length > 1) { // Every task should generate only one .resources. Log.LogErrorWithCodeFromResources(nameof(SR.MoreResourcesFiles)); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs index a57fc7eb8d5..f549b1592b7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs @@ -402,16 +402,10 @@ protected override void Dispose(bool disposing) FreeByteRangeDownloader(); // Free Event Handles - should not throw - if (_readEventHandles[(int)ReadEvent.FullDownloadReadEvent] != null) - { - _readEventHandles[(int)ReadEvent.FullDownloadReadEvent].Close(); - _readEventHandles[(int)ReadEvent.FullDownloadReadEvent] = null; - } - if (_readEventHandles[(int)ReadEvent.ByteRangeReadEvent] != null) - { - _readEventHandles[(int)ReadEvent.ByteRangeReadEvent].Close(); - _readEventHandles[(int)ReadEvent.ByteRangeReadEvent] = null; - } + _readEventHandles[(int)ReadEvent.FullDownloadReadEvent]?.Close(); + _readEventHandles[(int)ReadEvent.FullDownloadReadEvent] = null; + _readEventHandles[(int)ReadEvent.ByteRangeReadEvent]?.Close(); + _readEventHandles[(int)ReadEvent.ByteRangeReadEvent] = null; // Free Full Download _responseStream?.Close(); @@ -1167,11 +1161,8 @@ private void ReleaseFullDownloadResources() FreeByteRangeDownloader(); // release the full download read event as it is no longer needed - if (_readEventHandles[(int)ReadEvent.FullDownloadReadEvent] != null) - { - _readEventHandles[(int)ReadEvent.FullDownloadReadEvent].Close(); - _readEventHandles[(int)ReadEvent.FullDownloadReadEvent] = null; - } + _readEventHandles[(int)ReadEvent.FullDownloadReadEvent]?.Close(); + _readEventHandles[(int)ReadEvent.FullDownloadReadEvent] = null; } finally { @@ -1196,12 +1187,8 @@ private void FreeByteRangeDownloader() try { ((IDisposable)_byteRangeDownloader).Dispose(); - - if (_readEventHandles[(int)ReadEvent.ByteRangeReadEvent] != null) - { - _readEventHandles[(int)ReadEvent.ByteRangeReadEvent].Close(); - _readEventHandles[(int)ReadEvent.ByteRangeReadEvent] = null; - } + _readEventHandles[(int)ReadEvent.ByteRangeReadEvent]?.Close(); + _readEventHandles[(int)ReadEvent.ByteRangeReadEvent] = null; } finally { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs index 0456b5e3e79..1216a0d8e1d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs @@ -227,12 +227,9 @@ public void Dispose() // Since the constructor might create a null _nativeRecognizer, // here we have to make sure we do have some thing to dispose. // Otherwise just no-op. - if ( _nativeRecognizer != null ) - { - _nativeRecognizer.Dispose(); - _nativeRecognizer = null; - } - + _nativeRecognizer?.Dispose(); + _nativeRecognizer = null; + _disposed = true; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs index 26b5f604133..809e8c1feea 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/InputGestureCollection.cs @@ -356,12 +356,9 @@ public void Clear() { throw new NotSupportedException(SR.ReadOnlyInputGesturesCollection); } - - if (_innerGestureList != null) - { - _innerGestureList.Clear(); - _innerGestureList = null; - } + + _innerGestureList?.Clear(); + _innerGestureList = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs index a3d13cb2733..c3e97b1e937 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Cursor.cs @@ -116,11 +116,8 @@ public void Dispose() private void Dispose(bool disposing) { - if ( _cursorHandle != null ) - { - _cursorHandle.Dispose(); - _cursorHandle = null; - } + _cursorHandle?.Dispose(); + _cursorHandle = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputLanguageSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputLanguageSource.cs index c5f71533b8e..e1d4a93c264 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputLanguageSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputLanguageSource.cs @@ -82,11 +82,8 @@ public void Initialize() /// public void Uninitialize() { - if (_ipp != null) - { - _ipp.Uninitialize(); - _ipp = null; - } + _ipp?.Uninitialize(); + _ipp = null; } #endregion Public Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs index f28321c44cd..6dff5b1165a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputManager.cs @@ -625,12 +625,8 @@ internal static void CancelSynchronizedInput() _listeningElement = null; _synchronizedInputEvents = null; _pairedSynchronizedInputEvents = null; - - if (_synchronizedInputAsyncClearOperation != null) - { - _synchronizedInputAsyncClearOperation.Abort(); - _synchronizedInputAsyncClearOperation = null; - } + _synchronizedInputAsyncClearOperation?.Abort(); + _synchronizedInputAsyncClearOperation = null; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs index c884c431adc..cc1a847e01e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationLogic.cs @@ -285,11 +285,8 @@ private void OnInertiaTick(object sender, EventArgs e) private void ClearTimer() { - if (_inertiaTimer != null) - { - _inertiaTimer.Stop(); - _inertiaTimer = null; - } + _inertiaTimer?.Stop(); + _inertiaTimer = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs index 3836c2ebe72..a873eeb5860 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenThreadWorker.cs @@ -1246,8 +1246,7 @@ internal void ThreadProc() // we are doing this to compinsate for drivers that send a move after they send a outofrange for (int i = 0; i < _penContexts.Length; i++) { - PenContext penContext = _penContexts[i].Target as PenContext; - if (penContext != null) + if (_penContexts[i].Target is PenContext penContext) { // we send 0 as the stulyspointerId to trigger code in PenContext::FirePenOutOfRange penContext.FirePenOutOfRange(0, Environment.TickCount); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs index 5be11da6b70..e7bf6cd2fa5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndMouseInputProvider.cs @@ -409,11 +409,8 @@ internal IntPtr FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, Int // Abort the pending operation waiting to update the cursor, because we // are going to update it as part of this mouse move processing. - if (_queryCursorOperation != null) - { - _queryCursorOperation.Abort(); - _queryCursorOperation = null; - } + _queryCursorOperation?.Abort(); + _queryCursorOperation = null; // MITIGATION_SETCURSOR if (_haveCapture) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPanningFeedback.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPanningFeedback.cs index 70c1e8e5464..27b5da8123f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPanningFeedback.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPanningFeedback.cs @@ -109,11 +109,8 @@ public void EndPanningFeedback(bool animateBack) if (_hwndSource != null && _isProvidingPanningFeedback) { _isProvidingPanningFeedback = false; - if (_updatePanningOperation != null) - { - _updatePanningOperation.Abort(); - _updatePanningOperation = null; - } + _updatePanningOperation?.Abort(); + _updatePanningOperation = null; UnsafeNativeMethods.EndPanningFeedback(Handle, animateBack); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs index 4a5b428a098..bf7e07aae11 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs @@ -2563,11 +2563,8 @@ private void Dispose(bool disposing) // (see comment above about disposing the HwndStylusInputProvider) // { - if (_hwndTarget != null) - { - _hwndTarget.Dispose(); - _hwndTarget = null; - } + _hwndTarget?.Dispose(); + _hwndTarget = null; if (_hwndWrapper != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs index a938c561963..98c5c0c220c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs @@ -2567,11 +2567,8 @@ public void Dispose() MonitorPowerEvent = null; _hwndTargetCount = 0; - if (_notificationHwnd != null) - { - _notificationHwnd.Dispose(); - _notificationHwnd = null; - } + _notificationHwnd?.Dispose(); + _notificationHwnd = null; } public void AttachHwndTarget(HwndTarget hwndTarget) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ChannelManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ChannelManager.cs index d5d42a55b73..47ebe991c67 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ChannelManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ChannelManager.cs @@ -79,12 +79,9 @@ internal void RemoveSyncChannels() _freeSyncChannels = null; } - if (_syncServiceChannel != null) - { - _syncServiceChannel.Close(); + _syncServiceChannel?.Close(); - _syncServiceChannel = null; - } + _syncServiceChannel = null; } /// @@ -92,18 +89,11 @@ internal void RemoveSyncChannels() /// internal void RemoveChannels() { - if (_asyncChannel != null) - { - _asyncChannel.Close(); - _asyncChannel = null; - } + _asyncChannel?.Close(); + _asyncChannel = null; + _asyncOutOfBandChannel?.Close(); + _asyncOutOfBandChannel = null; - if (_asyncOutOfBandChannel != null) - { - _asyncOutOfBandChannel.Close(); - _asyncOutOfBandChannel = null; - } - RemoveSyncChannels(); if (_pSyncConnection != IntPtr.Zero) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs index bb3388cd2a5..dc042cda7aa 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs @@ -885,23 +885,15 @@ internal LineEnumerator(FormattedText text) _nextLine = null; _formatter = TextFormatter.FromCurrentDispatcher(text._textFormattingMode); _that = text; - if (_that._textSourceImpl == null) - _that._textSourceImpl = new TextSourceImplementation(_that); + _that._textSourceImpl ??= new TextSourceImplementation(_that); } public void Dispose() { - if (_currentLine != null) - { - _currentLine.Dispose(); - _currentLine = null; - } - - if (_nextLine != null) - { - _nextLine.Dispose(); - _nextLine = null; - } + _currentLine?.Dispose(); + _currentLine = null; + _nextLine?.Dispose(); + _nextLine = null; } internal int Position @@ -1035,11 +1027,8 @@ public bool MoveNext() if (!nextLineFits) { // next line doesn't fit - if (_nextLine != null) - { - _nextLine.Dispose(); - _nextLine = null; - } + _nextLine?.Dispose(); + _nextLine = null; if (_that._trimming != TextTrimming.None && !_currentLine.HasCollapsed) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/RenderTargetBitmap.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/RenderTargetBitmap.cs index c37d8eb8294..0524c2b6c26 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/RenderTargetBitmap.cs @@ -213,12 +213,8 @@ internal void RenderTargetContentsChanged() // this happens by throwing away our reference to the previous DUCE bitmap source // and forcing the creation of a new one. _isSourceCached = false; - - if (_convertedDUCEPtr != null) - { - _convertedDUCEPtr.Close(); - _convertedDUCEPtr = null; - } + _convertedDUCEPtr?.Close(); + _convertedDUCEPtr = null; // Register for update in the next render pass RegisterForAsyncUpdateResource(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs index f6ddd374ba6..04bdb1541b2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs @@ -1681,11 +1681,8 @@ internal void Resize(ICompositionTarget resizedCompositionTarget) // Cancel pending render queue items so that we don't dispatch them later // causing a double render during Resize. (Note that RenderMessage will schedule a // new RenderQueueItem). - if (_currentRenderOp != null) - { - _currentRenderOp.Abort(); - _currentRenderOp = null; - } + _currentRenderOp?.Abort(); + _currentRenderOp = null; // We don't need to keep our promotion timers around. _promoteRenderOpToInput.Stop(); @@ -1859,11 +1856,8 @@ private void RenderMessageHandlerCore( // We've processed the currentRenderOp so clear it // - if (_currentRenderOp != null) - { - _currentRenderOp.Abort(); - _currentRenderOp = null; - } + _currentRenderOp?.Abort(); + _currentRenderOp = null; if (!InterlockIsEnabled) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs index 8917034b2cc..6409919fdd9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/SafeMILHandle.cs @@ -61,12 +61,8 @@ internal void CopyMemoryPressure(SafeMILHandle original) protected override bool ReleaseHandle() { UnsafeNativeMethods.MILUnknown.ReleaseInterface(ref handle); - - if (_gcPressure != null) - { - _gcPressure.Release(); - _gcPressure = null; - } + _gcPressure?.Release(); + _gcPressure = null; return true; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/IconHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/IconHelper.cs index c7f026af65c..b14a75832de 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/IconHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/IconHelper.cs @@ -259,17 +259,11 @@ internal static NativeMethods.IconHandle CreateIconCursor( } finally { - if (colorBitmap != null) - { - colorBitmap.Dispose(); - colorBitmap = null; - } + colorBitmap?.Dispose(); + colorBitmap = null; - if (maskBitmap != null) - { - maskBitmap.Dispose(); - maskBitmap = null; - } + maskBitmap?.Dispose(); + maskBitmap = null; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXSite.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXSite.cs index d52aa28547b..bad6a4ff9b5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXSite.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/ActiveXSite.cs @@ -451,11 +451,8 @@ internal void StartEvents() internal void StopEvents() { - if (_connectionPoint != null) - { - _connectionPoint.Disconnect(); - _connectionPoint = null; - } + _connectionPoint?.Disconnect(); + _connectionPoint = null; } internal int OnActiveXRectChange(NativeMethods.COMRECT lprcPosRect) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs index 620e137e8b2..6a84fb9f3a1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs @@ -664,11 +664,8 @@ public IgnoreViewEventsHelper(EnumerableCollectionView parent) public void Dispose() { - if (_parent != null) - { - _parent.EndIgnoreEvents(); - _parent = null; - } + _parent?.EndIgnoreEvents(); + _parent = null; GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs index 12b2fa2764e..4adf9a6fdaa 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs @@ -352,12 +352,9 @@ IndexingFilterMarshaler corePropertiesFilterMarshaler // filter, else to indicate filtering is completed. // - if (_currentStream != null) - { - // Close the stream for the previous PackagePart. - _currentStream.Close(); - _currentStream = null; - } + // Close the stream for the previous PackagePart. + _currentStream?.Close(); + _currentStream = null; for (_currentFilter = null; _partIterator.MoveNext(); _currentFilter = null) { @@ -426,11 +423,8 @@ IndexingFilterMarshaler xamlFilterMarshaler break; } - if (_currentStream != null) - { - _currentStream.Close(); - _currentStream = null; - } + _currentStream?.Close(); + _currentStream = null; } if (_currentFilter == null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs index e43ae134506..00758cb245e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs @@ -603,16 +603,14 @@ private void ReleaseResources() _encryptedPackage.Close(); _encryptedPackage = null; } - else if (_package != null) + else { - _package.Close(); + _package?.Close(); _package = null; } - if (_packageStream != null) - { - _packageStream.Close(); - _packageStream = null; - } + + _packageStream?.Close(); + _packageStream = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs index d6152eed792..bdde543771b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParagraph.cs @@ -533,11 +533,9 @@ internal void FormatParaFinite( finally { // Destroy top margin collapsing state (not needed anymore). - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; + // When possible in the future, remove this workaround for PTS uninitialized variable. if (dvrSubTrackTopSpace > PTS.dvBottomUndefined / 2) { @@ -581,11 +579,8 @@ internal void FormatParaFinite( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS. - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; // Adjust fsbbox to account for margins fsbbox.fsrc.u -= mbp.MBPLeft; @@ -675,11 +670,8 @@ internal void FormatParaBottomless( finally { // Destroy top margin collapsing state (not needed anymore). - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; } if (fsfmtrbl != PTS.FSFMTRBL.fmtrblCollision) @@ -700,11 +692,8 @@ internal void FormatParaBottomless( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS. - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; // Take into accound MBPs and modify subtrack metrics dvrTopSpace = (mbp.BPTop != 0) ? marginTop : dvrSubTrackTopSpace; @@ -805,11 +794,8 @@ internal void UpdateBottomlessPara( finally { // Destroy top margin collapsing state (not needed anymore). - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; } if (fsfmtrbl != PTS.FSFMTRBL.fmtrblCollision) @@ -830,11 +816,8 @@ internal void UpdateBottomlessPara( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS. - if (mcsContainer != null) - { - mcsContainer.Dispose(); - mcsContainer = null; - } + mcsContainer?.Dispose(); + mcsContainer = null; // Take into accound MBPs and modify subtrack metrics dvrTopSpace = (mbp.BPTop != 0) ? marginTop : dvrSubTrackTopSpace; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs index 7275a35320a..1471afc9402 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParagraph.cs @@ -48,12 +48,8 @@ internal FigureParagraph(DependencyObject element, StructuralCache structuralCac public override void Dispose() { base.Dispose(); - - if (_mainTextSegment != null) - { - _mainTextSegment.Dispose(); - _mainTextSegment = null; - } + _mainTextSegment?.Dispose(); + _mainTextSegment = null; } #endregion Constructors diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs index 709c23f40c7..e8f26da8fc3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParagraph.cs @@ -52,12 +52,8 @@ internal override void UpdGetParaChange( public override void Dispose() { base.Dispose(); - - if (_mainTextSegment != null) - { - _mainTextSegment.Dispose(); - _mainTextSegment = null; - } + _mainTextSegment?.Dispose(); + _mainTextSegment = null; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs index 4def89f66df..40c1f19112f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Section.cs @@ -448,11 +448,8 @@ internal void InvalidateStructure() /// internal void DestroyStructure() { - if (_mainTextSegment != null) - { - _mainTextSegment.Dispose(); - _mainTextSegment = null; - } + _mainTextSegment?.Dispose(); + _mainTextSegment = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs index 539f5188510..805b766297f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/SubpageParagraph.cs @@ -40,12 +40,8 @@ internal SubpageParagraph(DependencyObject element, StructuralCache structuralCa public override void Dispose() { base.Dispose(); - - if(_mainTextSegment != null) - { - _mainTextSegment.Dispose(); - _mainTextSegment = null; - } + _mainTextSegment?.Dispose(); + _mainTextSegment = null; GC.SuppressFinalize(this); } @@ -174,11 +170,8 @@ internal unsafe void FormatParaFinite( } subpageHeight = Math.Max(1, subpageHeight - (marginTop + mbp.BPTop)); // Destroy top margin collapsing state (not needed anymore). - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } + mcsSubpage?.Dispose(); + mcsSubpage = null; } else { @@ -283,12 +276,8 @@ internal unsafe void FormatParaFinite( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS (see above). - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } - + mcsSubpage?.Dispose(); + mcsSubpage = null; // Update information about first/last chunk paraClient.SetChunkInfo(pbrkrecIn == IntPtr.Zero, pbrkrecOut == IntPtr.Zero); @@ -352,12 +341,11 @@ internal unsafe void FormatParaBottomless( subpageWidth = Math.Max(1, subpageWidth - (mbp.MBPLeft + mbp.MBPRight)); MarginCollapsingState.CollapseTopMargin(PtsContext, mbp, mcs, out mcsSubpage, out marginTop); + // Destroy top margin collapsing state (not needed anymore). - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } + mcsSubpage?.Dispose(); + mcsSubpage = null; + durSubpageMargin = subpageWidth; // Initialize column info @@ -412,11 +400,8 @@ internal unsafe void FormatParaBottomless( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS. - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } + mcsSubpage?.Dispose(); + mcsSubpage = null; if (PTS.ToBoolean(fsbbox.fDefined)) { @@ -512,12 +497,11 @@ internal unsafe void UpdateBottomlessPara( subpageWidth = Math.Max(1, subpageWidth - (mbp.MBPLeft + mbp.MBPRight)); MarginCollapsingState.CollapseTopMargin(PtsContext, mbp, mcs, out mcsSubpage, out marginTop); + // Destroy top margin collapsing state (not needed anymore). - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } + mcsSubpage?.Dispose(); + mcsSubpage = null; + durSubpageMargin = subpageWidth; // Initialize column info @@ -571,11 +555,8 @@ internal unsafe void UpdateBottomlessPara( // Since MCS returned by PTS is never passed back, destroy MCS provided by PTS. // If necessary, new MCS is created and passed back to PTS. - if (mcsSubpage != null) - { - mcsSubpage.Dispose(); - mcsSubpage = null; - } + mcsSubpage?.Dispose(); + mcsSubpage = null; if (PTS.ToBoolean(fsbbox.fDefined)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/Line.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/Line.cs index 7d84803639a..9d7fb272167 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/Line.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/Line.cs @@ -32,11 +32,8 @@ internal abstract class Line : TextSource, IDisposable public void Dispose() { // Dispose text line - if (_line != null) - { - _line.Dispose(); - _line = null; - } + _line?.Dispose(); + _line = null; GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/MonitorWrapper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/MonitorWrapper.cs index e32c9372ed7..962833311a8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/MonitorWrapper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Utility/MonitorWrapper.cs @@ -50,11 +50,8 @@ public MonitorHelper(MonitorWrapper monitorWrapper) public void Dispose() { - if (_monitorWrapper != null) - { - _monitorWrapper.Exit(); - _monitorWrapper = null; - } + _monitorWrapper?.Exit(); + _monitorWrapper = null; GC.SuppressFinalize(this); } private MonitorWrapper _monitorWrapper; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs index 8da3dea92f1..7e723fbbfa0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs @@ -1281,11 +1281,8 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) else if (!altKeyDown && _rubberBandSelector != null) { //Detach the Rubberband Selector - if (_rubberBandSelector != null) - { - _rubberBandSelector.DetachRubberbandSelector(); - _rubberBandSelector = null; - } + _rubberBandSelector?.DetachRubberbandSelector(); + _rubberBandSelector = null; DocumentViewerOwner.IsSelectionEnabled = true; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxLine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxLine.cs index 8003f2e26e6..5efbf4e2715 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxLine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxLine.cs @@ -54,11 +54,8 @@ internal TextBoxLine(TextBoxView owner) public void Dispose() { // Dispose text line - if (_line != null) - { - _line.Dispose(); - _line = null; - } + _line?.Dispose(); + _line = null; GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs index 86e3e968a59..b1c317420f3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationService.cs @@ -227,11 +227,8 @@ public void Disable() // If it hasn't been run yet, abort the pending operation. Still need to // unregister and unload annotations. They may have been loaded due to a // store event. - if (_asyncLoadOperation != null) - { - _asyncLoadOperation.Abort(); - _asyncLoadOperation = null; - } + _asyncLoadOperation?.Abort(); + _asyncLoadOperation = null; // Unregister for changes to the store - add/deletes/anchor changes - before // unloading annotations. We don't want any events between unloading and unregistering. @@ -998,16 +995,13 @@ private void UpdateAnnotations() } } - if (_asyncLoadFromListOperation != null) - { - //stop this one - we will set a new one in the queue - _asyncLoadFromListOperation.Abort(); - _asyncLoadFromListOperation = null; - } + //stop this one - we will set a new one in the queue + _asyncLoadFromListOperation?.Abort(); + _asyncLoadFromListOperation = null; - if ((attachedAnnotations != null) && (attachedAnnotations.Count > 0)) + if (attachedAnnotations?.Count > 0) LoadAnnotationsFromListAsync(attachedAnnotations); - } + } /// /// Mark all AnnotationAdorners that Annotate this element as Dirty diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs index 59509263221..753868532b5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DocumentAutomationPeer.cs @@ -41,11 +41,8 @@ public DocumentAutomationPeer(FrameworkContentElement owner) /// internal void OnDisconnected() { - if (_textPattern != null) - { - _textPattern.Dispose(); - _textPattern = null; - } + _textPattern?.Dispose(); + _textPattern = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs index d34f91d9531..a5b49ae2502 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs @@ -533,11 +533,8 @@ internal UpdateChildrenHelper(ItemsControlAutomationPeer peer) void IDisposable.Dispose() { - if (_peer != null) - { - _peer.ClearReusablePeers(_oldChildren); - _peer = null; - } + _peer?.ClearReusablePeers(_oldChildren); + _peer = null; } private ItemsControlAutomationPeer _peer; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs index 931135c26c3..11c03b629cc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ComboBox.cs @@ -679,12 +679,9 @@ private void TextUpdated(string newText, bool textBoxUpdated) // Try searching for an item matching the new text if (IsTextSearchEnabled) { - if (_updateTextBoxOperation != null) - { - // cancel any pending async update of the textbox - _updateTextBoxOperation.Abort(); - _updateTextBoxOperation = null; - } + // cancel any pending async update of the textbox + _updateTextBoxOperation?.Abort(); + _updateTextBoxOperation = null; MatchedTextInfo matchedTextInfo = TextSearch.FindMatchingPrefix(this, newText); int matchedIndex = matchedTextInfo.MatchedItemIndex; @@ -1208,11 +1205,8 @@ protected override void OnIsMouseCapturedChanged(DependencyPropertyChangedEventA } else { - if (_autoScrollTimer != null) - { - _autoScrollTimer.Stop(); - _autoScrollTimer = null; - } + _autoScrollTimer?.Stop(); + _autoScrollTimer = null; } base.OnIsMouseCapturedChanged(e); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs index 517b1d62355..0bc0b447bcf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs @@ -275,11 +275,8 @@ private Size DetermineRealizedColumnsBlockList(Size constraint) if (columnIndex != childIndex || previousColumnIndex != (columnIndex - 1)) { childIndex = columnIndex; - if (generatorState != null) - { - generatorState.Dispose(); - generatorState = null; - } + generatorState?.Dispose(); + generatorState = null; } previousColumnIndex = columnIndex; @@ -333,9 +330,9 @@ private Size DetermineRealizedColumnsBlockList(Size constraint) redeterminationNeeded = true; } } - else if (generatorState != null) + else { - generatorState.Dispose(); + generatorState?.Dispose(); generatorState = null; } @@ -398,11 +395,8 @@ private Size DetermineRealizedColumnsBlockList(Size constraint) } finally { - if (generatorState != null) - { - generatorState.Dispose(); - generatorState = null; - } + generatorState?.Dispose(); + generatorState = null; } // If we are virtualizing and datagrid doesnt have any star columns diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs index da390b401cc..300992fa518 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs @@ -96,11 +96,8 @@ internal void OnEnterParentTree() internal void OnExitParentTree() { _offset = 0; - if (_sharedState != null) - { - _sharedState.RemoveMember(this); - _sharedState = null; - } + _sharedState?.RemoveMember(this); + _sharedState = null; } /// @@ -509,13 +506,10 @@ private static void OnSharedSizeGroupPropertyChanged(DependencyObject d, Depende { string sharedSizeGroupId = (string) e.NewValue; - if (definition._sharedState != null) - { - // if definition is already registered AND shared size group id is changing, - // then un-register the definition from the current shared size state object. - definition._sharedState.RemoveMember(definition); - definition._sharedState = null; - } + // if definition is already registered AND shared size group id is changing, + // then un-register the definition from the current shared size state object. + definition._sharedState?.RemoveMember(definition); + definition._sharedState = null; if ((definition._sharedState == null) && (sharedSizeGroupId != null)) { @@ -591,13 +585,10 @@ private static void OnPrivateSharedSizeScopePropertyChanged(DependencyObject d, { SharedSizeScope privateSharedSizeScope = (SharedSizeScope) e.NewValue; - if (definition._sharedState != null) - { - // if definition is already registered And shared size scope is changing, - // then un-register the definition from the current shared size state object. - definition._sharedState.RemoveMember(definition); - definition._sharedState = null; - } + // if definition is already registered And shared size scope is changing, + // then un-register the definition from the current shared size state object. + definition._sharedState?.RemoveMember(definition); + definition._sharedState = null; if ((definition._sharedState == null) && (privateSharedSizeScope != null)) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs index 7eaf1c8159b..ac24a1e9d34 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs @@ -2499,11 +2499,8 @@ public DeferHelper(ItemCollection itemCollection) public void Dispose() { - if (_itemCollection != null) - { - _itemCollection.EndDefer(); - _itemCollection = null; - } + _itemCollection?.EndDefer(); + _itemCollection = null; GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs index 841491f7b90..26c42b51a79 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBox.cs @@ -625,11 +625,8 @@ protected override void OnIsMouseCapturedChanged(DependencyPropertyChangedEventA } else { - if (_autoScrollTimer != null) - { - _autoScrollTimer.Stop(); - _autoScrollTimer = null; - } + _autoScrollTimer?.Stop(); + _autoScrollTimer = null; } base.OnIsMouseCapturedChanged(e); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs index 7e7ac09b675..79e3acc2dfd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ListBoxItem.cs @@ -280,11 +280,8 @@ private void HandleMouseButtonDown(MouseButton mouseButton) protected override void OnMouseEnter(MouseEventArgs e) { // abort any drag operation we have queued. - if (parentNotifyDraggedOperation != null) - { - parentNotifyDraggedOperation.Abort(); - parentNotifyDraggedOperation = null; - } + parentNotifyDraggedOperation?.Abort(); + parentNotifyDraggedOperation = null; if (IsMouseOver) { @@ -305,11 +302,8 @@ protected override void OnMouseEnter(MouseEventArgs e) protected override void OnMouseLeave(MouseEventArgs e) { // abort any drag operation we have queued. - if (parentNotifyDraggedOperation != null) - { - parentNotifyDraggedOperation.Abort(); - parentNotifyDraggedOperation = null; - } + parentNotifyDraggedOperation?.Abort(); + parentNotifyDraggedOperation = null; base.OnMouseLeave(e); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs index 9f38c4f7592..f73ca58c285 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs @@ -2561,11 +2561,8 @@ private void SetTimerToCloseHierarchy() private void StopTimer(ref DispatcherTimer timer) { - if (timer != null) - { - timer.Stop(); - timer = null; - } + timer?.Stop(); + timer = null; } private void StartTimer(DispatcherTimer timer) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs index cb76325d478..952fa101ade 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs @@ -542,11 +542,8 @@ private void DismissKeyboardToolTips() private void DismissPendingToolTip() { - if (PendingToolTipTimer != null) - { - PendingToolTipTimer.Stop(); - PendingToolTipTimer = null; - } + PendingToolTipTimer?.Stop(); + PendingToolTipTimer = null; if (PendingToolTip != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs index 722f81600a6..7f88b405643 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs @@ -1721,20 +1721,14 @@ private bool SetupAnimations(bool visible) private void CancelAsyncCreate() { - if (_asyncCreate != null) - { - _asyncCreate.Abort(); - _asyncCreate = null; - } + _asyncCreate?.Abort(); + _asyncCreate = null; } private void CancelAsyncDestroy() { - if (_asyncDestroy != null) - { - _asyncDestroy.Stop(); - _asyncDestroy = null; - } + _asyncDestroy?.Stop(); + _asyncDestroy = null; } internal void ForceClose() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs index f566436b44d..ed188896c15 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs @@ -1832,11 +1832,8 @@ private void UninitializeRenderScope() } else if ((fdv = _renderScope as FlowDocumentView) != null) { - if (fdv.Document != null) - { - fdv.Document.Uninitialize(); - fdv.Document = null; - } + fdv.Document?.Uninitialize(); + fdv.Document = null; } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs index ba6f9302820..d0241f45e78 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs @@ -4630,11 +4630,8 @@ private void ClearMeasureCachesState() } } - if (_cleanupDelay != null) - { - _cleanupDelay.Stop(); - _cleanupDelay = null; - } + _cleanupDelay?.Stop(); + _cleanupDelay = null; } private void ClearIsScrollActive() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs index b9a6ef81c4e..cb2169d4ba9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WebBrowser.cs @@ -584,11 +584,8 @@ internal override void CreateSink() internal override void DetachSink() { //If we have a cookie get rid of it - if ( _cookie != null) - { - _cookie.Disconnect(); - _cookie = null; - } + _cookie?.Disconnect(); + _cookie = null; } internal override ActiveXSite CreateActiveXSite() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs index eb1690348bf..2de19b89915 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/CollectionView.cs @@ -2065,11 +2065,8 @@ public DeferHelper(CollectionView collectionView) public void Dispose() { - if (_collectionView != null) - { - _collectionView.EndDefer(); - _collectionView = null; - } + _collectionView?.EndDefer(); + _collectionView = null; GC.SuppressFinalize(this); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs index 1bd74149ebb..8659db5528c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CaretElement.cs @@ -571,12 +571,8 @@ internal void RefreshCaret(bool italic) internal void DetachFromView() { SetBlinking(/*isBlinkEnabled:*/false); - - if (_adornerLayer != null) - { - _adornerLayer.Remove(this); - _adornerLayer = null; - } + _adornerLayer?.Remove(this); + _adornerLayer = null; } internal void SetBlinking(bool isBlinkEnabled) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs index c5913f40f76..13174be604d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ColumnResizeAdorner.cs @@ -142,11 +142,8 @@ internal void Initialize(UIElement renderScope, double xPos, double yPos, double internal void Uninitialize() { - if (_adornerLayer != null) - { - _adornerLayer.Remove(this); - _adornerLayer = null; - } + _adornerLayer?.Remove(this); + _adornerLayer = null; } #endregion Internal methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs index 1af73f5253d..5e40b60a8a8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/CompositionAdorner.cs @@ -372,12 +372,9 @@ internal void Initialize(ITextView textView) /// internal void Uninitialize() { - if (_adornerLayer != null) - { - // Remove CompositionAdorner form the socping of AdornerLayer - _adornerLayer.Remove(this); - _adornerLayer = null; - } + // Remove CompositionAdorner form the socping of AdornerLayer + _adornerLayer?.Remove(this); + _adornerLayer = null; } #endregion Internal methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs index 8b6c018e08e..1cd439d8597 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs @@ -1219,11 +1219,8 @@ private void Initialize(TextContainer textContainer) _structuralCache = new StructuralCache(this, textContainer); // Get rid of the current formatter. - if (_formatter != null) - { - _formatter.Suspend(); - _formatter = null; - } + _formatter?.Suspend(); + _formatter = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs index 7da45ec65f3..3ff86af39ae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/ImmComposition.cs @@ -194,11 +194,8 @@ internal void CompleteComposition() UnsafeNativeMethods.ImmReleaseContext(new HandleRef(this, hwnd), new HandleRef(this, himc)); } - if (_compositionAdorner != null) - { - _compositionAdorner.Uninitialize(); - _compositionAdorner = null; - } + _compositionAdorner?.Uninitialize(); + _compositionAdorner = null; _startComposition = null; _endComposition = null; @@ -820,11 +817,8 @@ private void UpdateCompositionString(char[] resultChars, char[] compositionChars // // Remove any existing composition adorner for display attribute. // - if (_compositionAdorner != null) - { - _compositionAdorner.Uninitialize(); - _compositionAdorner = null; - } + _compositionAdorner?.Uninitialize(); + _compositionAdorner = null; // // Build up an array of resultChars + compositionChars -- the complete span of changing text. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs index c76ff6a817d..9b2cf94e313 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/InlineUIContainer.cs @@ -156,11 +156,8 @@ private void UpdateUIElementIsland() if(_uiElementIsland == null || _uiElementIsland.Root != childElement) { - if(_uiElementIsland != null) - { - _uiElementIsland.Dispose(); - _uiElementIsland = null; - } + _uiElementIsland?.Dispose(); + _uiElementIsland = null; if(childElement != null) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs index 64b77828a2c..b325005c344 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContent.cs @@ -141,11 +141,8 @@ public void GetPageRootAsyncCancel() #endif // VerifyAccess(); // Important: do not throw if no outstanding GetPageRootAsyncCall - if (_asyncOp != null) - { - _asyncOp.Cancel(); - _asyncOp = null; - } + _asyncOp?.Cancel(); + _asyncOp = null; } #endregion Public Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContentAsyncResult.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContentAsyncResult.cs index 6a0d53438a1..9596830aba0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContentAsyncResult.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/PageContentAsyncResult.cs @@ -232,11 +232,8 @@ internal FixedPage Result #region Private Methods private void _OnPaserFinished(object sender, EventArgs args) { - if (_pendingStream != null) - { - _pendingStream.Close(); - _pendingStream = null; - } + _pendingStream?.Close(); + _pendingStream = null; } #endregion Private Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs index 9c74f379b76..a1264c3a569 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Speller.cs @@ -86,11 +86,8 @@ internal void Detach() _statusTable = null; // Release our nl6 objects. - if (_spellerInterop != null) - { - _spellerInterop.Dispose(); - _spellerInterop = null; - } + _spellerInterop?.Dispose(); + _spellerInterop = null; // Clear the TextEditor. (Used as a sentinel to track Detachedness // from pending idle callback.) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs index e32c6dcce3e..a9fd89e76e9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextContainer.cs @@ -2690,11 +2690,8 @@ private int CutContent(TextPointer startPosition, TextPointer endPosition, out i } Invariant.Assert(middleSubTree.Role == SplayTreeNodeRole.LocalRoot, "middleSubTree is not a local root!"); - if (middleSubTree.ParentNode != null) - { - middleSubTree.ParentNode.ContainedNode = null; - middleSubTree.ParentNode = null; - } + middleSubTree.ParentNode?.ContainedNode = null; + middleSubTree.ParentNode = null; // Calc the symbol count of the middle tree. for (childNode = middleSubTree; childNode != null; childNode = childNode.RightChildNode) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs index 05e937dac71..2cb234e1e4e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextEditor.cs @@ -217,17 +217,11 @@ private void DetachTextStore(bool finalizer) // We don't need this TextStore any more. // TextStore needs to be unregisted from Cicero so clean all reference // of the native resources. - if (_textstore != null) - { - _textstore.OnDetach(finalizer); - _textstore = null; - } + _textstore?.OnDetach(finalizer); + _textstore = null; - if (_weakThis != null) - { - _weakThis.StopListening(); - _weakThis = null; - } + _weakThis?.StopListening(); + _weakThis = null; if (!finalizer) { @@ -1742,14 +1736,11 @@ private static void OnLostKeyboardFocus(object sender, KeyboardFocusChangedEvent // IMM32's OnLostFocus handler. Clean the composition string if it exists. if (_immEnabled) { - if (This._immComposition != null) - { - // Call ImmComposition OnLostFocus to clean up the event handler(SelectionChanged). - This._immComposition.OnLostFocus(); + // Call ImmComposition OnLostFocus to clean up the event handler(SelectionChanged). + This._immComposition?.OnLostFocus(); - // Set _immComposition as null not to access it until get new from the getting focus. - This._immComposition = null; - } + // Set _immComposition as null not to access it until get new from the getting focus. + This._immComposition = null; } } @@ -1778,11 +1769,8 @@ private static void OnLostFocus(object sender, RoutedEventArgs e) TextEditorTyping._BreakTypingSequence(This); // Release column resizing adorner, and interrupt table resising process (if any) - if (This._tableColResizeInfo != null) - { - This._tableColResizeInfo.DisposeAdorner(); - This._tableColResizeInfo = null; - } + This._tableColResizeInfo?.DisposeAdorner(); + This._tableColResizeInfo = null; // Hide selection This._selection.UpdateCaretAndHighlight(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeEditTables.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeEditTables.cs index b4c9d9a5e57..6cb741342c0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeEditTables.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRangeEditTables.cs @@ -1778,11 +1778,8 @@ internal void ResizeColumn(Point mousePoint) // Must be called to remove table resizing adorned from a render scope internal void DisposeAdorner() { - if (_tableColResizeAdorner != null) - { - _tableColResizeAdorner.Uninitialize(); - _tableColResizeAdorner = null; - } + _tableColResizeAdorner?.Uninitialize(); + _tableColResizeAdorner = null; } internal double LeftDragMax { get { return (_dxl); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs index 66232f32362..e57b691266e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextSelection.cs @@ -2585,11 +2585,8 @@ private static DependencyObject GetParentElement(DependencyObject element) // Removes the caret from the visual tree. private void DetachCaretFromVisualTree() { - if (_caretElement != null) - { - _caretElement.DetachFromView(); - _caretElement = null; - } + _caretElement?.DetachFromView(); + _caretElement = null; } #endregion Private methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs index a0deecf9357..94cf4ac7800 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextServicesDisplayAttributePropertyRanges.cs @@ -101,11 +101,8 @@ internal override void OnEndEdit(UnsafeNativeMethods.ITfContext context, // Remove any existing composition adorner for display attribute. // - if (_compositionAdorner != null) - { - _compositionAdorner.Uninitialize(); - _compositionAdorner = null; - } + _compositionAdorner?.Uninitialize(); + _compositionAdorner = null; // // Look for new ones. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinEventHandler.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinEventHandler.cs index cccd2d36c25..bd42476a495 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinEventHandler.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/WinEventHandler.cs @@ -99,11 +99,8 @@ internal void Stop() _hHook = IntPtr.Zero ; } - if (_shutdownListener != null) - { - _shutdownListener.StopListening(); - _shutdownListener = null; - } + _shutdownListener?.StopListening(); + _shutdownListener = null; } #endregion Internal Methods diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs index d393302fa0b..892eee06208 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs @@ -498,11 +498,9 @@ protected virtual void Dispose(bool disposing) PresentationSource.RemoveSourceChangedHandler(this, new SourceChangedEventHandler(OnSourceChanged)); } - if (_weakEventDispatcherShutdown != null) // Can be null if the static ctor failed ... see WebBrowser. - { - _weakEventDispatcherShutdown.Dispose(); - _weakEventDispatcherShutdown = null; - } + // Can be null if the static ctor failed ... see WebBrowser. + _weakEventDispatcherShutdown?.Dispose(); + _weakEventDispatcherShutdown = null; DestroyWindow(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs index a1c0695fb04..4e794ea4408 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlMapTable.cs @@ -1710,11 +1710,8 @@ private TypeConverter GetConverterFromCache(Type type) internal void ClearConverterCache() { // clear the Type converterCache to reduce survived memory allocs - if (_converterCache != null) - { - _converterCache.Clear(); - _converterCache = null; - } + _converterCache?.Clear(); + _converterCache = null; } #endif diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs index 9a1ff43c2aa..69148e8dd9e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs @@ -307,11 +307,8 @@ internal System.Text.Encoding Encoding /// internal void Close() { - if (_xmlReader != null) - { - _xmlReader.Close(); - _xmlReader = null; - } + _xmlReader?.Close(); + _xmlReader = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs index 4a7cc4df030..5823fb0826e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Navigation/NavigationService.cs @@ -2484,11 +2484,8 @@ private void HandleLoadCompleted(object navState) // some scenarios. // Do not close and null it before firing LoadCompleted because we pass webresponse out in Navigated and LoadCompleted event args. - if (_webResponse != null) - { - _webResponse.Close(); - _webResponse = null; - } + _webResponse?.Close(); + _webResponse = null; if (!isNavInitiator && ncParent != null) { @@ -2935,11 +2932,8 @@ private void GetObjectFromResponse(WebRequest request, WebResponse response, Uri { response.Close(); _webResponse = null; - if (_asyncObjectConverter != null) - { - _asyncObjectConverter.CancelAsync(); - _asyncObjectConverter = null; - } + _asyncObjectConverter?.CancelAsync(); + _asyncObjectConverter = null; } } } @@ -4347,11 +4341,8 @@ internal void Stop() // and the ones in progress. // Abort dispatched navigation operations - if (_postedOp != null) - { - _postedOp.Abort(); - _postedOp = null; - } + _postedOp?.Abort(); + _postedOp = null; } internal Uri Source diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs index 4650ba7de11..57f3f338df4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs @@ -1782,11 +1782,8 @@ internal override Type GetValueType() // remove this DeferredResourceReference from its ResourceDictionary internal virtual void RemoveFromDictionary() { - if (_dictionary != null) - { - _dictionary.RemoveDeferredResourceReference(this); - _dictionary = null; - } + _dictionary?.RemoveDeferredResourceReference(this); + _dictionary = null; } internal void AddInflatedListener(ResourceReferenceExpression listener) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index 968f11bc460..257eed0b24c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -2360,11 +2360,8 @@ private void InternalDispose() // a WM_DESTROY msg and it is a duplicate msg. // When the window is closing, stop any deferred operations. - if (_taskbarRetryTimer != null) - { - _taskbarRetryTimer.Stop(); - _taskbarRetryTimer = null; - } + _taskbarRetryTimer?.Stop(); + _taskbarRetryTimer = null; try { @@ -4433,12 +4430,9 @@ private void DoDialogHide() //before _dispatcherFrame is instantiated. In the Activated handler, if user closes the //window (setting DialogResult fires the WM_CLOSE event), the _dispatcherFrame is still null. //Bug 874463 addressed this. - if (_dispatcherFrame != null) - { - // un block the push frame call - _dispatcherFrame.Continue = false; - _dispatcherFrame = null; - } + // un block the push frame call + _dispatcherFrame?.Continue = false; + _dispatcherFrame = null; // Fix for Close Dialog Window should not return null // @@ -7642,9 +7636,9 @@ internal void UpdatePanningFeedback(Vector totalOverpanOffset, bool animate) _panningFeedback = new HwndPanningFeedback(_sourceWindow); } - // Update the window position - _panningFeedback?.UpdatePanningFeedback(totalOverpanOffset, animate); - } + // Update the window position + _panningFeedback?.UpdatePanningFeedback(totalOverpanOffset, animate); + } /// /// Return the window back to its original position. @@ -7652,12 +7646,9 @@ internal void UpdatePanningFeedback(Vector totalOverpanOffset, bool animate) /// Whether to animate to the original position. internal void EndPanningFeedback(bool animateBack) { - if (_panningFeedback != null) - { - // Restore the window to its original position - _panningFeedback.EndPanningFeedback(animateBack); - _panningFeedback = null; - } + // Restore the window to its original position + _panningFeedback?.EndPanningFeedback(animateBack); + _panningFeedback = null; } private HwndSource _sourceWindow; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/Document.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/Document.cs index 9d8364a100a..11606200804 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/Document.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/Document.cs @@ -135,11 +135,8 @@ protected virtual void Dispose(bool disposing) ThrowIfDisposed(); _isDisposed = true; #endif - if (_dependency != null) - { - _dependency.Dispose(); - _dependency = null; - } + _dependency?.Dispose(); + _dependency = null; } } #endregion IDisposable Members diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PackageDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PackageDocument.cs index 803dc29f3a4..3ab95455656 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PackageDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/PackageDocument.cs @@ -88,11 +88,8 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (Package != null) - { - Package.Close(); - Package = null; - } + Package?.Close(); + Package = null; } } finally diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsDocument.cs index 05a90ebc7e6..6b1ccec76d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/RightsDocument.cs @@ -141,19 +141,13 @@ protected override void Dispose(bool disposing) { try { - if (WorkspacePackage != null) - { - WorkspacePackage.Close(); - WorkspacePackage = null; - } + WorkspacePackage?.Close(); + WorkspacePackage = null; } finally { - if (SourcePackage != null) - { - SourcePackage.Close(); - SourcePackage = null; - } + SourcePackage?.Close(); + SourcePackage = null; } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamDocument.cs index db4c88885b4..8c3fdea28b3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamDocument.cs @@ -110,19 +110,13 @@ protected void ReleaseStreams() { try { - if (WorkspaceProxy != null) - { - WorkspaceProxy.Close(); + WorkspaceProxy?.Close(); WorkspaceProxy = null; - } } finally { - if (SourceProxy != null) - { - SourceProxy.Close(); + SourceProxy?.Close(); SourceProxy = null; - } } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs index 8a15211961b..f15fc6e8539 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/RightsManagementProvider.cs @@ -1289,11 +1289,8 @@ private void InitializeMembers() /// private void CleanUpSecureEnvironment() { - if (_secureEnvironment != null) - { - _secureEnvironment.Dispose(); - _secureEnvironment = null; - } + _secureEnvironment?.Dispose(); + _secureEnvironment = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs index 83e28e45a9e..15d07d83efd 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/AlphaFlattener/MetroDevice.cs @@ -740,11 +740,8 @@ private byte[] ConvertPrintTicketToDevMode(PrintTicket ticket) private void DisposePrintTicketConverter() { - if (m_Converter != null) - { - m_Converter.Dispose(); - m_Converter = null; - } + m_Converter?.Dispose(); + m_Converter = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/COMPSTUISRID.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/COMPSTUISRID.cs index fb3be1344d1..9f9cabb715e 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/COMPSTUISRID.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/COMPSTUISRID.cs @@ -60,12 +60,9 @@ public string Get(uint srid) public void Release() { - SafeModuleHandle handle = this._compstuiHandle; - if (this._compstuiHandle != null) - { - this._compstuiHandle.Dispose(); - this._compstuiHandle = null; - } + SafeModuleHandle handle = this._compstuiHandle; + this._compstuiHandle?.Dispose(); + this._compstuiHandle = null; } private SafeModuleHandle EnsureModuleHandle() diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/WinSpoolPrinterCapabilities.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/WinSpoolPrinterCapabilities.cs index f51c822b3d4..32d22129985 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/WinSpoolPrinterCapabilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/MS/Internal/Printing/Configuration/WinSpoolPrinterCapabilities.cs @@ -35,11 +35,8 @@ public WinSpoolPrinterCapabilities(string deviceName, string driverName, string public void Release() { - if (this._devMode != null) - { - this._devMode.Dispose(); - this._devMode = null; - } + this._devMode?.Dispose(); + this._devMode = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs index f3aef8a886d..3106c4c26f8 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/PartEditor.cs @@ -299,17 +299,12 @@ string namespaceUri Close( ) { - if (null != _xmlWriter) - { - _xmlWriter.Close(); - _xmlWriter = null; - } + _xmlWriter?.Close(); + _xmlWriter = null; + + _xmlReader?.Close(); + _xmlReader = null; - if (null != _xmlReader) - { - _xmlReader.Close(); - _xmlReader = null; - } base.Close(); } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs index 6665f11545f..ed2127f96e1 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/FallbackPTProvider.cs @@ -656,11 +656,8 @@ protected override void Dispose(bool disposing) if (disposing) { - if (_deviceHandle != null) - { - _deviceHandle.Dispose(); - _deviceHandle = null; - } + _deviceHandle?.Dispose(); + _deviceHandle = null; _deviceName = null; _driverName = null; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTManager.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTManager.cs index ad74facbc62..917d71d2616 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTManager.cs @@ -446,11 +446,8 @@ protected virtual void Dispose(bool disposing) if (disposing) { - if (_ptProvider != null) - { - _ptProvider.Dispose(); - _ptProvider = null; - } + _ptProvider?.Dispose(); + _ptProvider = null; } _disposed = true; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs index cf10901b7ee..e8d3f6905ad 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PTProvider.cs @@ -534,11 +534,8 @@ protected override void Dispose(bool disposing) if (disposing) { - if (_providerHandle != null) - { - _providerHandle.Dispose(); - _providerHandle = null; - } + _providerHandle?.Dispose(); + _providerHandle = null; _deviceName = null; _schemaVersion = 0; diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrintCapabilitesWriter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrintCapabilitesWriter.cs index c81cde37c94..4a79208065c 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrintCapabilitesWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PrintCapabilitesWriter.cs @@ -51,13 +51,9 @@ public void Release() this._writer = null; } - if (this._strings != null) - { - // Security Critical call - this._strings.Release(); - - this._strings = null; - } + // Security Critical call + this._strings?.Release(); + this._strings = null; } public void Flush() diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs index 0b903253ff2..b6533038942 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs @@ -621,11 +621,8 @@ XmlWriter xmlWriter _serializationManager.PackagingPolicy.PreCommitCurrentPage(); - if (_treeWalker != null) - { - _treeWalker.CommitHyperlinks(); - _treeWalker = null; - } + _treeWalker?.CommitHyperlinks(); + _treeWalker = null; xmlWriter.WriteEndElement(); diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs index aa8dcb89b09..34930a05d39 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGalleryCategoriesPanel.cs @@ -40,11 +40,8 @@ public RibbonGalleryCategoriesPanel() private void OnRibbonGalleryCategoriesPanelUnloaded(object sender, RoutedEventArgs e) { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; - if (iContainsStarLayoutManager.StarLayoutManager != null) - { - iContainsStarLayoutManager.StarLayoutManager.UnregisterStarLayoutProvider(this); - iContainsStarLayoutManager.StarLayoutManager = null; - } + iContainsStarLayoutManager.StarLayoutManager?.UnregisterStarLayoutProvider(this); + iContainsStarLayoutManager.StarLayoutManager = null; } private void OnRibbonGalleryCategoriesPanelLoaded(object sender, RoutedEventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGroupItemsPanel.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGroupItemsPanel.cs index 02f5a9b3480..5664392e42e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGroupItemsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGroupItemsPanel.cs @@ -116,11 +116,8 @@ protected override Size ArrangeOverride(Size finalSize) private void OnRibbonGroupItemsPanelUnloaded(object sender, RoutedEventArgs e) { IContainsStarLayoutManager iContainsStarLayoutManager = (IContainsStarLayoutManager)this; - if (iContainsStarLayoutManager.StarLayoutManager != null) - { - iContainsStarLayoutManager.StarLayoutManager.UnregisterStarLayoutProvider(this); - iContainsStarLayoutManager.StarLayoutManager = null; - } + iContainsStarLayoutManager.StarLayoutManager?.UnregisterStarLayoutProvider(this); + iContainsStarLayoutManager.StarLayoutManager = null; } private static double GetStarChildMinWidth(FrameworkElement child, ref double maxStarColumnWidth) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs index dc4251a707b..9f5573bac5d 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonComboBox.cs @@ -666,12 +666,9 @@ private void TextUpdated(string newText, bool textBoxUpdated) if (IsTextSearchEnabled && _firstGallery != null) { #if RIBBON_IN_FRAMEWORK - if (_updateTextBoxOperation != null) - { - // cancel any pending async update of the textbox - _updateTextBoxOperation.Abort(); - _updateTextBoxOperation = null; - } + // cancel any pending async update of the textbox + _updateTextBoxOperation?.Abort(); + _updateTextBoxOperation = null; #endif ItemsControl matchedGalleryCategory = null; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs index fa120bf6f36..e75a590e55b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuItem.cs @@ -1152,11 +1152,8 @@ internal void SetTimerToCloseSubmenu() private static void StopTimer(ref DispatcherTimer timer) { - if (timer != null) - { - timer.Stop(); - timer = null; - } + timer?.Stop(); + timer = null; } private void StartTimer(DispatcherTimer timer) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationProcessor2D.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationProcessor2D.cs index 4c4d195ccd0..6df221a8e07 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationProcessor2D.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Input.Manipulations/System/Windows/Input/Manipulations/ManipulationProcessor2D.cs @@ -295,11 +295,8 @@ public void ProcessManipulators(Int64 timestamp, IEnumerable mani /// previous timestamp for the current manipulation. public void CompleteManipulation(Int64 timestamp) { - if (this.currentManipulation != null) - { - this.currentManipulation.CompleteManipulation(timestamp); - this.currentManipulation = null; - } + this.currentManipulation?.CompleteManipulation(timestamp); + this.currentManipulation = null; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs index 1fc3e82aee9..d05192d8949 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs @@ -548,11 +548,8 @@ public void Dispose() { Debug.Assert( _request != null ); - if( _request != null ) - { - _request.Pop(); - _request = null; - } + _request?.Pop(); + _request = null; } // No finalizer - usually Dispose is used with a finalizer, diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs index 5831784ec20..de28152733b 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Security/RightsManagement/IssuanceLicense.cs @@ -819,14 +819,11 @@ private void GetIssuanceLicenseInfo( out officialFlagTemp); Errors.ThrowOnErrorCode(hr); - if (ownerHandleTemp != null) - { - // As a result of calling DRMGetIssuanceLicenseInfo twice, - // we are getting 2 handles. We are going to dispose the first one - // and preserve the second one. - ownerHandleTemp.Dispose(); - ownerHandleTemp = null; - } + // As a result of calling DRMGetIssuanceLicenseInfo twice, + // we are getting 2 handles. We are going to dispose the first one + // and preserve the second one. + ownerHandleTemp?.Dispose(); + ownerHandleTemp = null; StringBuilder distributionPointNameTemp = null; // allocate memory as necessary, it seems that Unmanaged libraries really do not like diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs index e259b785fe8..5ac01f004ad 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageRoot.cs @@ -373,13 +373,10 @@ internal void Close() { if( null == rootIStorage ) return; // Extraneous calls to Close() are ignored - - if( null != dataSpaceManager ) - { - // Tell data space manager to flush all information as necessary - dataSpaceManager.Dispose(); - dataSpaceManager = null; - } + + // Tell data space manager to flush all information as necessary + dataSpaceManager?.Dispose(); + dataSpaceManager = null; try { diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Data/DataSourceProvider.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Data/DataSourceProvider.cs index 6ca93b29c80..f2dbe8fa6b7 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Data/DataSourceProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Data/DataSourceProvider.cs @@ -406,11 +406,8 @@ public DeferHelper(DataSourceProvider provider) public void Dispose() { GC.SuppressFinalize(this); - if (_provider != null) - { - _provider.EndDefer(); - _provider = null; - } + _provider?.EndDefer(); + _provider = null; } private DataSourceProvider _provider; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs index 3e3055e3b8c..23db52b0875 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs @@ -186,12 +186,9 @@ public void Stop() updateWin32Timer = true; // If the operation is in the queue, abort it. - if(_operation != null) - { - _operation.Abort(); - _operation = null; - } -} + _operation?.Abort(); + _operation = null; + } } if(updateWin32Timer) diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs index a222bc7d90d..65b2042ea4f 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ElementHost.cs @@ -826,11 +826,8 @@ protected override void Dispose(bool disposing) { try { - if (_hostContainerInternal != null) - { - _hostContainerInternal.Dispose(); - _hostContainerInternal = null; - } + _hostContainerInternal?.Dispose(); + _hostContainerInternal = null; } finally {