Skip to content

Commit effb908

Browse files
committed
enable nullable on BaseClient and SftpClient
1 parent 5b9c669 commit effb908

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

src/Renci.SshNet/BaseClient.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Net.Sockets;
34
using System.Threading;
45
using System.Threading.Tasks;
@@ -22,7 +23,7 @@ public abstract class BaseClient : IBaseClient
2223
private readonly IServiceFactory _serviceFactory;
2324
private readonly object _keepAliveLock = new object();
2425
private TimeSpan _keepAliveInterval;
25-
private Timer _keepAliveTimer;
26+
private Timer? _keepAliveTimer;
2627
private ConnectionInfo _connectionInfo;
2728
private bool _isDisposed;
2829

@@ -32,7 +33,7 @@ public abstract class BaseClient : IBaseClient
3233
/// <value>
3334
/// The current session.
3435
/// </value>
35-
internal ISession Session { get; private set; }
36+
internal ISession? Session { get; private set; }
3637

3738
/// <summary>
3839
/// Gets the factory for creating new services.
@@ -142,17 +143,17 @@ public TimeSpan KeepAliveInterval
142143
/// <summary>
143144
/// Occurs when an error occurred.
144145
/// </summary>
145-
public event EventHandler<ExceptionEventArgs> ErrorOccurred;
146+
public event EventHandler<ExceptionEventArgs>? ErrorOccurred;
146147

147148
/// <summary>
148149
/// Occurs when host key received.
149150
/// </summary>
150-
public event EventHandler<HostKeyEventArgs> HostKeyReceived;
151+
public event EventHandler<HostKeyEventArgs>? HostKeyReceived;
151152

152153
/// <summary>
153154
/// Occurs when server identification received.
154155
/// </summary>
155-
public event EventHandler<SshIdentificationEventArgs> ServerIdentificationReceived;
156+
public event EventHandler<SshIdentificationEventArgs>? ServerIdentificationReceived;
156157

157158
/// <summary>
158159
/// Initializes a new instance of the <see cref="BaseClient"/> class.
@@ -193,7 +194,7 @@ private protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionI
193194
throw new ArgumentNullException(nameof(serviceFactory));
194195
}
195196

196-
ConnectionInfo = connectionInfo;
197+
_connectionInfo = connectionInfo;
197198
_ownsConnectionInfo = ownsConnectionInfo;
198199
_serviceFactory = serviceFactory;
199200
_keepAliveInterval = SshNet.Session.InfiniteTimeSpan;
@@ -381,17 +382,17 @@ protected virtual void OnDisconnected()
381382
{
382383
}
383384

384-
private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
385+
private void Session_ErrorOccured(object? sender, ExceptionEventArgs e)
385386
{
386387
ErrorOccurred?.Invoke(this, e);
387388
}
388389

389-
private void Session_HostKeyReceived(object sender, HostKeyEventArgs e)
390+
private void Session_HostKeyReceived(object? sender, HostKeyEventArgs e)
390391
{
391392
HostKeyReceived?.Invoke(this, e);
392393
}
393394

394-
private void Session_ServerIdentificationReceived(object sender, SshIdentificationEventArgs e)
395+
private void Session_ServerIdentificationReceived(object? sender, SshIdentificationEventArgs e)
395396
{
396397
ServerIdentificationReceived?.Invoke(this, e);
397398
}
@@ -422,14 +423,12 @@ protected virtual void Dispose(bool disposing)
422423

423424
Disconnect();
424425

425-
if (_ownsConnectionInfo && _connectionInfo is not null)
426+
if (_ownsConnectionInfo)
426427
{
427428
if (_connectionInfo is IDisposable connectionInfoDisposable)
428429
{
429430
connectionInfoDisposable.Dispose();
430431
}
431-
432-
_connectionInfo = null;
433432
}
434433

435434
_isDisposed = true;

src/Renci.SshNet/IBaseClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Net.Sockets;
34
using System.Threading;
45
using System.Threading.Tasks;

src/Renci.SshNet/ISftpClient.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#nullable enable
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Text;
@@ -211,7 +212,7 @@ public interface ISftpClient : IBaseClient
211212
/// <remarks>
212213
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
213214
/// </remarks>
214-
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object state, Action<ulong> downloadCallback = null);
215+
IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object? state, Action<ulong>? downloadCallback = null);
215216

216217
/// <summary>
217218
/// Begins an asynchronous operation of retrieving list of files in remote directory.
@@ -224,7 +225,7 @@ public interface ISftpClient : IBaseClient
224225
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
225226
/// </returns>
226227
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
227-
IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state, Action<int> listCallback = null);
228+
IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object? state, Action<int>? listCallback = null);
228229

229230
/// <summary>
230231
/// Begins the synchronize directories.
@@ -240,7 +241,7 @@ public interface ISftpClient : IBaseClient
240241
/// <exception cref="ArgumentNullException"><paramref name="sourcePath"/> is <see langword="null"/>.</exception>
241242
/// <exception cref="ArgumentException"><paramref name="destinationPath"/> is <see langword="null"/> or contains only whitespace.</exception>
242243
/// <exception cref="SshException">If a problem occurs while copying the file.</exception>
243-
IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback asyncCallback, object state);
244+
IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destinationPath, string searchPattern, AsyncCallback asyncCallback, object? state);
244245

245246
/// <summary>
246247
/// Begins an asynchronous uploading the stream into remote file.
@@ -316,7 +317,7 @@ public interface ISftpClient : IBaseClient
316317
/// If the remote file already exists, it is overwritten and truncated.
317318
/// </para>
318319
/// </remarks>
319-
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
320+
IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback, object? state, Action<ulong>? uploadCallback = null);
320321

321322
/// <summary>
322323
/// Begins an asynchronous uploading the stream into remote file.
@@ -343,7 +344,7 @@ public interface ISftpClient : IBaseClient
343344
/// <see cref="SshException"/>.
344345
/// </para>
345346
/// </remarks>
346-
IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null);
347+
IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback asyncCallback, object? state, Action<ulong>? uploadCallback = null);
347348

348349
/// <summary>
349350
/// Changes remote directory to path.
@@ -522,7 +523,7 @@ public interface ISftpClient : IBaseClient
522523
/// <remarks>
523524
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
524525
/// </remarks>
525-
void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null);
526+
void DownloadFile(string path, Stream output, Action<ulong>? downloadCallback = null);
526527

527528
/// <summary>
528529
/// Ends an asynchronous file downloading into the stream.
@@ -700,7 +701,7 @@ public interface ISftpClient : IBaseClient
700701
/// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
701702
/// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
702703
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
703-
IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallback = null);
704+
IEnumerable<ISftpFile> ListDirectory(string path, Action<int>? listCallback = null);
704705

705706
/// <summary>
706707
/// Asynchronously enumerates the files in remote directory.
@@ -1006,7 +1007,7 @@ public interface ISftpClient : IBaseClient
10061007
/// <remarks>
10071008
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
10081009
/// </remarks>
1009-
void UploadFile(Stream input, string path, Action<ulong> uploadCallback = null);
1010+
void UploadFile(Stream input, string path, Action<ulong>? uploadCallback = null);
10101011

10111012
/// <summary>
10121013
/// Uploads stream into remote file.
@@ -1024,7 +1025,7 @@ public interface ISftpClient : IBaseClient
10241025
/// <remarks>
10251026
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
10261027
/// </remarks>
1027-
void UploadFile(Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null);
1028+
void UploadFile(Stream input, string path, bool canOverride, Action<ulong>? uploadCallback = null);
10281029

10291030
/// <summary>
10301031
/// Writes the specified byte array to the specified file, and closes the file.

0 commit comments

Comments
 (0)