diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebRequestSession.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebRequestSession.cs index 4e58503659e..d4a9a5cc48b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebRequestSession.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/WebRequestSession.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#nullable enable + using System; using System.Collections.Generic; using System.Net; @@ -16,12 +18,14 @@ namespace Microsoft.PowerShell.Commands /// public class WebRequestSession : IDisposable { - private HttpClient _client; + #region Fields + + private HttpClient? _client; private CookieContainer _cookies; private bool _useDefaultCredentials; - private ICredentials _credentials; - private X509CertificateCollection _certificates; - private IWebProxy _proxy; + private ICredentials? _credentials; + private X509CertificateCollection? _certificates; + private IWebProxy? _proxy; private int _maximumRedirection; private WebSslProtocol _sslProtocol; private bool _allowAutoRedirect; @@ -35,6 +39,8 @@ public class WebRequestSession : IDisposable /// private bool _disposedClient; + #endregion Fields + /// /// Gets or sets the Header property. /// @@ -61,15 +67,15 @@ public class WebRequestSession : IDisposable /// /// Gets or sets the Credentials property. /// - public ICredentials Credentials { get => _credentials; set => SetClassVar(ref _credentials, value); } + public ICredentials? Credentials { get => _credentials; set => SetClassVar(ref _credentials, value); } /// /// Gets or sets the Certificates property. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public X509CertificateCollection Certificates { get => _certificates; set => SetClassVar(ref _certificates, value); } + public X509CertificateCollection? Certificates { get => _certificates; set => SetClassVar(ref _certificates, value); } - #endregion + #endregion Credentials /// /// Gets or sets the UserAgent property. @@ -79,7 +85,7 @@ public class WebRequestSession : IDisposable /// /// Gets or sets the Proxy property. /// - public IWebProxy Proxy + public IWebProxy? Proxy { get => _proxy; set @@ -238,7 +244,7 @@ private HttpClient CreateHttpClient() }; } - private void SetClassVar(ref T oldValue, T newValue) where T : class + private void SetClassVar(ref T oldValue, T newValue) where T : class? { if (oldValue != newValue) {