Use preferred overloads of string.Split() (#23712)
* Use preferred overloads of string.Split * Revert TrimEntries for netstandard2.0 Revert usage of StringSplit.TrimEntries for projects that target netstandard2.0. Co-authored-by: Levi Broderick <levib@microsoft.com>
This commit is contained in:
parent
a738d1ccfb
commit
fd1f1c3559
|
|
@ -76,21 +76,8 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
|
|
||||||
private IReadOnlyList<string> Split(string value)
|
private IReadOnlyList<string> Split(string value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
return value?.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
|
||||||
{
|
?? Array.Empty<string>();
|
||||||
return Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var list = new List<string>();
|
|
||||||
foreach (var part in value.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
|
||||||
{
|
|
||||||
var trimmedPart = part;
|
|
||||||
if (!string.IsNullOrEmpty(trimmedPart))
|
|
||||||
{
|
|
||||||
list.Add(trimmedPart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var arguments = !string.IsNullOrEmpty(argumentString)
|
var arguments = argumentString?.Split(',', StringSplitOptions.TrimEntries) ?? Array.Empty<string>();
|
||||||
? argumentString.Split(',').Select(argument => argument.Trim()).ToArray()
|
|
||||||
: Array.Empty<string>();
|
|
||||||
|
|
||||||
// We want to find the constructors that match the number of passed in arguments
|
// We want to find the constructors that match the number of passed in arguments
|
||||||
// We either want a single match, or a single best match. The best match is the one with the most
|
// We either want a single match, or a single best match. The best match is the one with the most
|
||||||
|
|
|
||||||
|
|
@ -71,15 +71,6 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> SplitString(string original)
|
private static IEnumerable<string> SplitString(string original)
|
||||||
{
|
=> original?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
|
||||||
if (string.IsNullOrEmpty(original))
|
|
||||||
{
|
|
||||||
return Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var split = original.Split(',').Select(piece => piece.Trim()).Where(piece => !string.IsNullOrEmpty(piece));
|
|
||||||
|
|
||||||
return split;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,19 +173,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> SplitAndTrimPropertyNames(string original)
|
private static IEnumerable<string> SplitAndTrimPropertyNames(string original)
|
||||||
{
|
=> original?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
|
||||||
if (string.IsNullOrEmpty(original))
|
|
||||||
{
|
|
||||||
return Array.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var split = original
|
|
||||||
.Split(',')
|
|
||||||
.Select(piece => piece.Trim())
|
|
||||||
.Where(trimmed => !string.IsNullOrEmpty(trimmed));
|
|
||||||
|
|
||||||
return split;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckForLocalizer(ClientModelValidationContext context)
|
private void CheckForLocalizer(ClientModelValidationContext context)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue