Skip to content

Replace IsNullOrWhiteSpace extension #1142

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 1 commit into from
Jun 12, 2023
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
4 changes: 1 addition & 3 deletions src/Renci.SshNet/AuthenticationMethod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;

using Renci.SshNet.Common;

namespace Renci.SshNet
{
/// <summary>
Expand Down Expand Up @@ -34,7 +32,7 @@ public abstract class AuthenticationMethod : IAuthenticationMethod
/// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or <c>null</c>.</exception>
protected AuthenticationMethod(string username)
{
if (username.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(username))
{
throw new ArgumentException("username");
}
Expand Down
25 changes: 0 additions & 25 deletions src/Renci.SshNet/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ namespace Renci.SshNet.Common
/// </summary>
internal static partial class Extensions
{
/// <summary>
/// Determines whether the specified value is null or white space.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>
/// <c>true</c> if <paramref name="value"/> is null or white space; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrWhiteSpace(this string value)
{
if (string.IsNullOrEmpty(value))
{
return true;
}

for (var i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}

return true;
}

internal static byte[] ToArray(this ServiceName serviceName)
{
switch (serviceName)
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/ScpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void Upload(Stream source, string path)
/// <exception cref="SshException">The secure copy execution request was rejected by the server.</exception>
public void Download(string filename, Stream destination)
{
if (filename.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(filename))
{
throw new ArgumentException(Message);
}
Expand Down
26 changes: 13 additions & 13 deletions src/Renci.SshNet/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void CreateDirectory(string path)
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException(path);
}
Expand Down Expand Up @@ -355,7 +355,7 @@ public void DeleteDirectory(string path)
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -384,7 +384,7 @@ public void DeleteFile(string path)
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -415,7 +415,7 @@ public async Task DeleteFileAsync(string path, CancellationToken cancellationTok
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -542,12 +542,12 @@ public void SymbolicLink(string path, string linkPath)
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}

if (linkPath.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(linkPath))
{
throw new ArgumentException("linkPath");
}
Expand Down Expand Up @@ -753,7 +753,7 @@ public bool Exists(string path)
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -882,7 +882,7 @@ public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback
{
CheckDisposed();

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -1109,7 +1109,7 @@ public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride,
throw new ArgumentNullException(nameof(input));
}

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -2106,7 +2106,7 @@ public IEnumerable<FileInfo> SynchronizeDirectories(string sourcePath, string de
throw new ArgumentNullException(nameof(sourcePath));
}

if (destinationPath.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(destinationPath))
{
throw new ArgumentException("destinationPath");
}
Expand Down Expand Up @@ -2135,7 +2135,7 @@ public IAsyncResult BeginSynchronizeDirectories(string sourcePath, string destin
throw new ArgumentNullException(nameof(sourcePath));
}

if (destinationPath.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(destinationPath))
{
throw new ArgumentException("destDir");
}
Expand Down Expand Up @@ -2340,7 +2340,7 @@ private void InternalDownloadFile(string path, Stream output, SftpDownloadAsyncR
throw new ArgumentNullException(nameof(output));
}

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down Expand Up @@ -2404,7 +2404,7 @@ private void InternalUploadFile(Stream input, string path, Flags flags, SftpUplo
throw new ArgumentNullException(nameof(input));
}

if (path.IsNullOrWhiteSpace())
if (string.IsNullOrWhiteSpace(path))
{
throw new ArgumentException("path");
}
Expand Down