Skip to content

Move IDisposable implementation declaration from inheritees to parent #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Renci.SshNet/AuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Renci.SshNet
/// <summary>
/// Base class for all supported authentication methods.
/// </summary>
public abstract class AuthenticationMethod : IAuthenticationMethod
public abstract class AuthenticationMethod : IAuthenticationMethod, IDisposable
{
/// <summary>
/// Gets the name of the authentication method.
Expand Down Expand Up @@ -61,5 +61,23 @@ AuthenticationResult IAuthenticationMethod.Authenticate(ISession session)
{
return Authenticate((Session)session);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true"/> to release both managed and unmanaged resources;
/// <see langword="false"/> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
}

/// <inheritdoc/>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
20 changes: 5 additions & 15 deletions src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Renci.SshNet
/// <summary>
/// Provides functionality to perform keyboard interactive authentication.
/// </summary>
public class KeyboardInteractiveAuthenticationMethod : AuthenticationMethod, IDisposable
public class KeyboardInteractiveAuthenticationMethod : AuthenticationMethod
{
private readonly RequestMessageKeyboardInteractive _requestMessage;
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
Expand Down Expand Up @@ -151,20 +151,8 @@ private void Session_UserAuthenticationInformationRequestReceived(object sender,
});
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -182,6 +170,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
}
}
7 changes: 2 additions & 5 deletions src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,9 @@ protected virtual void Dispose(bool disposing)
{
if (AuthenticationMethods != null)
{
foreach (var authenticationMethods in AuthenticationMethods)
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethods is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down
20 changes: 5 additions & 15 deletions src/Renci.SshNet/NoneAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Renci.SshNet
/// <summary>
/// Provides functionality for "none" authentication method.
/// </summary>
public class NoneAuthenticationMethod : AuthenticationMethod, IDisposable
public class NoneAuthenticationMethod : AuthenticationMethod
{
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private EventWaitHandle _authenticationCompleted = new AutoResetEvent(initialState: false);
Expand Down Expand Up @@ -87,20 +87,8 @@ private void Session_UserAuthenticationFailureReceived(object sender, MessageEve
_ = _authenticationCompleted.Set();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -118,6 +106,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
}
}
20 changes: 5 additions & 15 deletions src/Renci.SshNet/PasswordAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Renci.SshNet
/// <summary>
/// Provides functionality to perform password authentication.
/// </summary>
public class PasswordAuthenticationMethod : AuthenticationMethod, IDisposable
public class PasswordAuthenticationMethod : AuthenticationMethod
{
private readonly RequestMessagePassword _requestMessage;
private readonly byte[] _password;
Expand Down Expand Up @@ -163,20 +163,8 @@ private void Session_UserAuthenticationPasswordChangeRequiredReceived(object sen
});
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -194,6 +182,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}
}
}
5 changes: 1 addition & 4 deletions src/Renci.SshNet/PasswordConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ protected virtual void Dispose(bool disposing)
{
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethod is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down
20 changes: 5 additions & 15 deletions src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Renci.SshNet
/// <summary>
/// Provides functionality to perform private key authentication.
/// </summary>
public class PrivateKeyAuthenticationMethod : AuthenticationMethod, IDisposable
public class PrivateKeyAuthenticationMethod : AuthenticationMethod
{
private AuthenticationResult _authenticationResult = AuthenticationResult.Failure;
private EventWaitHandle _authenticationCompleted = new ManualResetEvent(initialState: false);
Expand Down Expand Up @@ -155,20 +155,8 @@ private void Session_UserAuthenticationPublicKeyReceived(object sender, MessageE
_ = _authenticationCompleted.Set();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (_isDisposed)
{
Expand All @@ -186,6 +174,8 @@ protected virtual void Dispose(bool disposing)

_isDisposed = true;
}

base.Dispose(disposing);
}

private sealed class SignatureData : SshData
Expand Down
5 changes: 1 addition & 4 deletions src/Renci.SshNet/PrivateKeyConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ protected virtual void Dispose(bool disposing)
{
foreach (var authenticationMethod in AuthenticationMethods)
{
if (authenticationMethod is IDisposable disposable)
{
disposable.Dispose();
}
authenticationMethod.Dispose();
}
}

Expand Down