Skip to content

Commit

Permalink
Fix more warnings reported by CodeAnalysis (#3393)
Browse files Browse the repository at this point in the history
* fix string warnings raised by CodeAnalysis
  • Loading branch information
heng-liu committed Jun 19, 2020
1 parent 668e7d0 commit 679f549
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,11 @@ private HashSet<string> WriteFiles(ZipArchive package, HashSet<string> filesWith
}
else
{
#if NETCOREAPP
filesWithoutExtensions.Add($"/{file.Path.Replace("\\", "/", StringComparison.Ordinal)}");
#else
filesWithoutExtensions.Add($"/{file.Path.Replace("\\", "/")}");
#endif
}
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public static IEnumerable<string> GetFiles(this ZipArchive zipArchive)
private static string UnescapePath(string path)
{
if (path != null
#if NETCOREAPP
&& path.IndexOf('%', StringComparison.Ordinal) > -1)
#else
&& path.IndexOf('%') > -1)
#endif
{
return Uri.UnescapeDataString(path);
}
Expand Down
4 changes: 4 additions & 0 deletions src/NuGet.Core/NuGet.Packaging/PackageFolderReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ public override IEnumerable<string> GetFiles(string folder)
/// </summary>
private static bool IsFileInRoot(string path)
{
#if NETCOREAPP
return path.IndexOf('/', StringComparison.Ordinal) == -1;
#else
return path.IndexOf('/') == -1;
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ internal class ConventionViolator

public ConventionViolator(string filePath, string extension, string expectedFile)
{
#if NETCOREAPP
Path = filePath.Replace(filePath.Split('/')[filePath.Count(p => p == '/')], string.Empty, StringComparison.OrdinalIgnoreCase);
#else
Path = filePath.Replace(filePath.Split('/')[filePath.Count(p => p == '/')], string.Empty);
#endif
Extension = extension;
ExpectedPath = expectedFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ private static void ThrowByteSignatureNotFoundException(byte[] signature)
throw new InvalidDataException(
string.Format(CultureInfo.CurrentCulture,
Strings.ErrorByteSignatureNotFound,
#if NETCOREAPP
BitConverter.ToString(signature).Replace("-", "", StringComparison.Ordinal)));
#else
BitConverter.ToString(signature).Replace("-", "")));
#endif
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public Dictionary<string, string> ReadSection()

private static KeyValuePair<string, string> GetProperty(string line)
{
#if NETCOREAPP
var pos = line.IndexOf(':', StringComparison.Ordinal);
#else
var pos = line.IndexOf(':');
#endif

if (pos > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public static DerGeneralizedTime Read(string decodedTime)
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

#if NETCOREAPP
var decimalIndex = decodedTime.IndexOf('.', StringComparison.Ordinal);
#else
var decimalIndex = decodedTime.IndexOf('.');
#endif
var stringToParse = decodedTime;
string format;

Expand Down Expand Up @@ -88,4 +92,4 @@ public static DerGeneralizedTime Read(string decodedTime)
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static bool TryReadTSTInfoFromSignedCms(
out IRfc3161TimestampTokenInfo tstInfo)
{
tstInfo = null;
if (timestampCms.ContentInfo.ContentType.Value.Equals(Oids.TSTInfoContentType))
if (timestampCms.ContentInfo.ContentType.Value.Equals(Oids.TSTInfoContentType, StringComparison.Ordinal))
{
tstInfo = Rfc3161TimestampTokenInfoFactory.Create(timestampCms.ContentInfo.Content);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ public static string GetHashString(X509Certificate2 certificate, HashAlgorithmNa
}

var certificateFingerprint = GetHash(certificate, hashAlgorithm);
#if NETCOREAPP
return BitConverter.ToString(certificateFingerprint).Replace("-", "", StringComparison.Ordinal);
#else
return BitConverter.ToString(certificateFingerprint).Replace("-", "");
#endif
}

/// <summary>
Expand Down Expand Up @@ -325,7 +329,11 @@ public static bool IsSelfIssued(X509Certificate2 certificate)
if (reader.HasTag(keyIdentifierTag))
{
var keyIdentifier = reader.ReadValue(keyIdentifierTag);
#if NETCOREAPP
var akiKeyIdentifier = BitConverter.ToString(keyIdentifier).Replace("-", "", StringComparison.Ordinal);
#else
var akiKeyIdentifier = BitConverter.ToString(keyIdentifier).Replace("-", "");
#endif

return string.Equals(skiExtension.SubjectKeyIdentifier, akiKeyIdentifier, StringComparison.OrdinalIgnoreCase);
}
Expand All @@ -347,4 +355,4 @@ public static IReadOnlyList<byte[]> GetRawDataForCollection(X509Certificate2Coll
return certificatesRawData.AsReadOnly();
}
}
}
}

0 comments on commit 679f549

Please sign in to comment.