Skip to content

Commit 23bbd59

Browse files
committed
RECS0127: Expression can be replaced with 'string.IsNullOrEmpty()'
1 parent 5691240 commit 23bbd59

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

ICSharpCode.SharpZipLib.Samples/cs/sz/sz.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static string InterpretExternalAttributes(int operatingSystem, int attributes)
195195
static bool IsNumeric(string rhs)
196196
{
197197
bool result;
198-
if ((rhs != null) && (rhs.Length > 0)) {
198+
if (!string.IsNullOrEmpty(rhs)) {
199199
result = true;
200200
for (int i = 0; result && (i < rhs.Length); ++i) {
201201
if (!char.IsDigit(rhs[i])) {
@@ -614,7 +614,7 @@ void ListZip(string fileName) {
614614

615615
using (FileStream fileStream = File.OpenRead(fileName)) {
616616
using (ZipInputStream stream = new ZipInputStream(fileStream)) {
617-
if ((password != null) && (password.Length > 0)) {
617+
if (!string.IsNullOrEmpty(password)) {
618618
stream.Password = password;
619619
}
620620

@@ -756,7 +756,7 @@ void List(ArrayList fileSpecifications)
756756
string [] names;
757757
string pathName = Path.GetDirectoryName(spec);
758758

759-
if ( (pathName == null) || (pathName.Length == 0) ) {
759+
if ( string.IsNullOrEmpty(pathName)) {
760760
pathName = @".\";
761761
}
762762
names = Directory.GetFiles(pathName, Path.GetFileName(spec));
@@ -792,7 +792,7 @@ static public string CookZipEntryName(string name, string stripPrefix, bool rela
792792
return "";
793793
}
794794

795-
if (stripPrefix != null && stripPrefix.Length > 0 && name.IndexOf(stripPrefix, 0) == 0) {
795+
if (!string.IsNullOrEmpty(stripPrefix)&& name.IndexOf(stripPrefix, 0) == 0) {
796796
name = name.Substring(stripPrefix.Length);
797797
}
798798

@@ -963,7 +963,7 @@ void Create(ArrayList fileSpecifications)
963963

964964
using (FileStream stream = File.Create(zipFileName)) {
965965
using (outputStream = new ZipOutputStream(stream)) {
966-
if ((password != null) && (password.Length > 0)) {
966+
if (!string.IsNullOrEmpty(password)) {
967967
outputStream.Password = password;
968968
}
969969

@@ -973,7 +973,7 @@ void Create(ArrayList fileSpecifications)
973973
string fileName = Path.GetFileName(spec);
974974
string pathName = Path.GetDirectoryName(spec);
975975

976-
if (pathName == null || pathName.Length == 0) {
976+
if (string.IsNullOrEmpty(pathName)) {
977977
pathName = Path.GetFullPath(".");
978978
if (relativePathInfo == true) {
979979
removablePathPrefix = pathName;
@@ -1132,7 +1132,7 @@ bool DecompressFile(string fileName, string targetDir)
11321132
/// </summary>
11331133
void Extract(ArrayList fileSpecifications)
11341134
{
1135-
if (targetOutputDirectory == null || targetOutputDirectory.Length == 0) {
1135+
if (string.IsNullOrEmpty(targetOutputDirectory)) {
11361136
targetOutputDirectory = @".\";
11371137
}
11381138

@@ -1142,7 +1142,7 @@ void Extract(ArrayList fileSpecifications)
11421142
if (spec.IndexOf('*') >= 0 || spec.IndexOf('?') >= 0) {
11431143
string pathName = Path.GetDirectoryName(spec);
11441144

1145-
if (pathName == null || pathName.Length == 0) {
1145+
if (string.IsNullOrEmpty(pathName)) {
11461146
pathName = @".\";
11471147
}
11481148
names = Directory.GetFiles(pathName, Path.GetFileName(spec));

ICSharpCode.SharpZipLib.Samples/cs/tar/tar.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ public void ShowTarProgressMessage(TarArchive archive, TarEntry entry, string me
279279
else {
280280
if (this.verbose) {
281281
string modeString = DecodeType(entry.TarHeader.TypeFlag, entry.Name.EndsWith("/")) + DecodeMode(entry.TarHeader.Mode);
282-
string userString = (entry.UserName == null || entry.UserName.Length == 0) ? entry.UserId.ToString() : entry.UserName;
283-
string groupString = (entry.GroupName == null || entry.GroupName.Length == 0) ? entry.GroupId.ToString() : entry.GroupName;
282+
string userString = (string.IsNullOrEmpty(entry.UserName)) ? entry.UserId.ToString() : entry.UserName;
283+
string groupString = (string.IsNullOrEmpty(entry.GroupName)) ? entry.GroupId.ToString() : entry.GroupName;
284284

285285
Console.WriteLine(string.Format("{0} {1}/{2} {3,8} {4:yyyy-MM-dd HH:mm:ss} {5}", modeString, userString, groupString, entry.Size, entry.ModTime.ToLocalTime(), entry.Name));
286286
} else {
@@ -341,7 +341,7 @@ int ProcessArguments(string[] args)
341341
} else if (arg.Equals("--compress")) {
342342
compression = Compression.Compress;
343343
} else if (arg.Equals("--blocking-factor")) {
344-
if (argValue == null || argValue.Length == 0)
344+
if (string.IsNullOrEmpty(argValue))
345345
Console.Error.WriteLine("expected numeric blocking factor");
346346
else {
347347
try {
@@ -359,7 +359,7 @@ int ProcessArguments(string[] args)
359359
} else if (arg.Equals("--keep-old-files")) {
360360
keepOldFiles = true;
361361
} else if (arg.Equals("--record-size")) {
362-
if (argValue == null || argValue.Length == 0) {
362+
if (string.IsNullOrEmpty(argValue)) {
363363
Console.Error.WriteLine("expected numeric record size");
364364
bailOut = true;
365365
} else {
@@ -479,7 +479,7 @@ int ProcessArguments(string[] args)
479479
static string[] GetFilesForSpec(string spec)
480480
{
481481
string dir = Path.GetDirectoryName(spec);
482-
if (dir == null || dir.Length == 0)
482+
if (string.IsNullOrEmpty(dir))
483483
dir = Directory.GetCurrentDirectory();
484484

485485
return System.IO.Directory.GetFiles(dir, Path.GetFileName(spec));

ICSharpCode.SharpZipLib.Samples/cs/zf/zf.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ void List(ArrayList fileSpecs)
585585
{
586586
string pathName = Path.GetDirectoryName(spec);
587587

588-
if ( (pathName == null) || (pathName.Length == 0) )
588+
if ( string.IsNullOrEmpty(pathName))
589589
{
590590
pathName = @".\";
591591
}
@@ -862,7 +862,7 @@ bool DecompressArchive(string fileName, string targetDir)
862862
/// </summary>
863863
void Extract(ArrayList fileSpecs)
864864
{
865-
if ( (targetOutputDirectory_ == null) || (targetOutputDirectory_.Length == 0) )
865+
if ( string.IsNullOrEmpty(targetOutputDirectory_))
866866
{
867867
targetOutputDirectory_ = @".\";
868868
}
@@ -875,7 +875,7 @@ void Extract(ArrayList fileSpecs)
875875
{
876876
string pathName = Path.GetDirectoryName(spec);
877877

878-
if ( (pathName == null) || (pathName.Length == 0) )
878+
if ( string.IsNullOrEmpty(pathName))
879879
{
880880
pathName = @".\";
881881
}
@@ -1334,7 +1334,7 @@ static string InterpretExternalAttributes(int operatingSystem, int attributes)
13341334
static bool IsNumeric(string rhs)
13351335
{
13361336
bool result;
1337-
if (rhs != null && rhs.Length > 0)
1337+
if (!string.IsNullOrEmpty(rhs))
13381338
{
13391339
result = true;
13401340
for (int i = 0; i < rhs.Length; ++i)

0 commit comments

Comments
 (0)