Skip to content

Commit 5195233

Browse files
committed
Use extension members for ThrowHelper
1 parent 6a23a9a commit 5195233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+227
-262
lines changed

src/Renci.SshNet/Abstractions/ThreadAbstraction.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
using Renci.SshNet.Common;
6-
75
namespace Renci.SshNet.Abstractions
86
{
97
internal static class ThreadAbstraction
@@ -18,7 +16,7 @@ internal static class ThreadAbstraction
1816
/// </returns>
1917
public static Task ExecuteThreadLongRunning(Action action)
2018
{
21-
ThrowHelper.ThrowIfNull(action);
19+
ArgumentNullException.ThrowIfNull(action);
2220

2321
return Task.Factory.StartNew(action,
2422
CancellationToken.None,
@@ -32,7 +30,7 @@ public static Task ExecuteThreadLongRunning(Action action)
3230
/// <param name="action">The action to execute.</param>
3331
public static void ExecuteThread(Action action)
3432
{
35-
ThrowHelper.ThrowIfNull(action);
33+
ArgumentNullException.ThrowIfNull(action);
3634

3735
_ = ThreadPool.QueueUserWorkItem(o => action());
3836
}

src/Renci.SshNet/AuthenticationMethod.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22

3-
using Renci.SshNet.Common;
4-
53
namespace Renci.SshNet
64
{
75
/// <summary>
@@ -36,7 +34,7 @@ public abstract class AuthenticationMethod : IAuthenticationMethod, IDisposable
3634
/// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or <see langword="null"/>.</exception>
3735
protected AuthenticationMethod(string username)
3836
{
39-
ThrowHelper.ThrowIfNullOrWhiteSpace(username);
37+
ArgumentException.ThrowIfNullOrWhiteSpace(username);
4038

4139
Username = username;
4240
}

src/Renci.SshNet/BaseClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
186186
/// </remarks>
187187
private protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory)
188188
{
189-
ThrowHelper.ThrowIfNull(connectionInfo);
190-
ThrowHelper.ThrowIfNull(serviceFactory);
189+
ArgumentNullException.ThrowIfNull(connectionInfo);
190+
ArgumentNullException.ThrowIfNull(serviceFactory);
191191

192192
_connectionInfo = connectionInfo;
193193
_ownsConnectionInfo = ownsConnectionInfo;
@@ -467,7 +467,7 @@ protected virtual void Dispose(bool disposing)
467467
/// <exception cref="ObjectDisposedException">The current instance is disposed.</exception>
468468
protected void CheckDisposed()
469469
{
470-
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
470+
ObjectDisposedException.ThrowIf(_isDisposed, this);
471471
}
472472

473473
/// <summary>

src/Renci.SshNet/ClientAuthentication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ internal int PartialSuccessLimit
5252
/// <exception cref="SshAuthenticationException">Failed to authenticate the client.</exception>
5353
public void Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
5454
{
55-
ThrowHelper.ThrowIfNull(connectionInfo);
56-
ThrowHelper.ThrowIfNull(session);
55+
ArgumentNullException.ThrowIfNull(connectionInfo);
56+
ArgumentNullException.ThrowIfNull(session);
5757

5858
session.RegisterMessage("SSH_MSG_USERAUTH_FAILURE");
5959
session.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS");

src/Renci.SshNet/Common/ChannelDataEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class ChannelDataEventArgs : ChannelEventArgs
1616
public ChannelDataEventArgs(uint channelNumber, byte[] data)
1717
: base(channelNumber)
1818
{
19-
ThrowHelper.ThrowIfNull(data);
19+
ArgumentNullException.ThrowIfNull(data);
2020

2121
Data = data;
2222
}

src/Renci.SshNet/Common/ChannelInputStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public override void Write(byte[] buffer, int offset, int count)
106106
#endif
107107
ValidateBufferArguments(buffer, offset, count);
108108

109-
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
109+
ObjectDisposedException.ThrowIf(_isDisposed, this);
110110

111111
if (count == 0)
112112
{

src/Renci.SshNet/Common/ChannelRequestEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal sealed class ChannelRequestEventArgs : EventArgs
1616
/// <exception cref="ArgumentNullException"><paramref name="info"/> is <see langword="null"/>.</exception>
1717
public ChannelRequestEventArgs(RequestInfo info)
1818
{
19-
ThrowHelper.ThrowIfNull(info);
19+
ArgumentNullException.ThrowIfNull(info);
2020

2121
Info = info;
2222
}

src/Renci.SshNet/Common/Extensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ internal static void ValidatePort(this int value, [CallerArgumentExpression(name
206206
/// </remarks>
207207
public static byte[] Take(this byte[] value, int offset, int count)
208208
{
209-
ThrowHelper.ThrowIfNull(value);
209+
ArgumentNullException.ThrowIfNull(value);
210210

211211
if (count == 0)
212212
{
@@ -238,7 +238,7 @@ public static byte[] Take(this byte[] value, int offset, int count)
238238
/// </remarks>
239239
public static byte[] Take(this byte[] value, int count)
240240
{
241-
ThrowHelper.ThrowIfNull(value);
241+
ArgumentNullException.ThrowIfNull(value);
242242

243243
if (count == 0)
244244
{
@@ -257,8 +257,8 @@ public static byte[] Take(this byte[] value, int count)
257257

258258
public static bool IsEqualTo(this byte[] left, byte[] right)
259259
{
260-
ThrowHelper.ThrowIfNull(left);
261-
ThrowHelper.ThrowIfNull(right);
260+
ArgumentNullException.ThrowIfNull(left);
261+
ArgumentNullException.ThrowIfNull(right);
262262

263263
return left.AsSpan().SequenceEqual(right);
264264
}
@@ -272,7 +272,7 @@ public static bool IsEqualTo(this byte[] left, byte[] right)
272272
/// </returns>
273273
public static byte[] TrimLeadingZeros(this byte[] value)
274274
{
275-
ThrowHelper.ThrowIfNull(value);
275+
ArgumentNullException.ThrowIfNull(value);
276276

277277
for (var i = 0; i < value.Length; i++)
278278
{

src/Renci.SshNet/Common/HostKeyEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public string FingerPrintMD5
9797
/// <exception cref="ArgumentNullException"><paramref name="host"/> is <see langword="null"/>.</exception>
9898
public HostKeyEventArgs(KeyHostAlgorithm host)
9999
{
100-
ThrowHelper.ThrowIfNull(host);
100+
ArgumentNullException.ThrowIfNull(host);
101101

102102
CanTrust = true;
103103
HostKey = host.KeyData.GetBytes();

src/Renci.SshNet/Common/PacketDump.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static string Create(List<byte> data, int indentLevel)
1414

1515
public static string Create(byte[] data, int indentLevel)
1616
{
17-
ThrowHelper.ThrowIfNull(data);
18-
ThrowHelper.ThrowIfNegative(indentLevel);
17+
ArgumentNullException.ThrowIfNull(data);
18+
ArgumentOutOfRangeException.ThrowIfNegative(indentLevel);
1919

2020
const int lineWidth = 16;
2121

0 commit comments

Comments
 (0)