Skip to content

Update SDK #33187

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 17 commits into from
Jun 10, 2021
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
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ dotnet_diagnostic.CA1840.severity = warning
dotnet_diagnostic.CA1841.severity = warning

# CA1845: Use span-based 'string.Concat'
dotnet_diagnostic.CA1845.severity = warning
dotnet_diagnostic.CA1845.severity = suggestion

# CA1846: Prefer AsSpan over Substring
dotnet_diagnostic.CA1846.severity = warning
Expand Down Expand Up @@ -186,5 +186,10 @@ dotnet_diagnostic.CA1837.severity = suggestion
dotnet_diagnostic.CA1838.severity = suggestion
# CA1841: Prefer Dictionary.Contains methods
dotnet_diagnostic.CA1841.severity = suggestion
# CA1845: Use span-based 'string.Concat'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @captainsafia I made a small change to your PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see -- didn't realize these were meant to be ordered.

dotnet_diagnostic.CA1845.severity = suggestion
# CA1846: Prefer AsSpan over Substring
dotnet_diagnostic.CA1846.severity = suggestion
# CA2012: Use ValueTask correctly
dotnet_diagnostic.CA2012.severity = suggestion

4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "6.0.100-preview.5.21264.3"
"version": "6.0.100-preview.6.21308.9"
},
"tools": {
"dotnet": "6.0.100-preview.5.21264.3",
"dotnet": "6.0.100-preview.6.21308.9",
"runtimes": {
"dotnet/x64": [
"2.1.27",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/WebView/WebView/src/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public QueryString Add(QueryString other)
}

// ?name1=value1 Add ?name2=value2 returns ?name1=value1&name2=value2
return new QueryString(Value + "&" + other.Value.Substring(1));
return new QueryString(string.Concat(Value, "&", other.Value.AsSpan(1)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
<ILLinkTreatWarningsAsErrors>false</ILLinkTreatWarningsAsErrors>
<!-- Revert after issue in https://github.com/dotnet/aspnetcore/pull/33187 is resolved. -->
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public QueryString Add(QueryString other)
}

// ?name1=value1 Add ?name2=value2 returns ?name1=value1&name2=value2
return new QueryString(Value + "&" + other.Value.Substring(1));
return new QueryString(string.Concat(Value, "&", other.Value.AsSpan(1)));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task PathMatchAction_BranchTaken(string matchPath, string basePath,
await app.Invoke(context);

Assert.Equal(200, context.Response.StatusCode);
Assert.Equal(basePath + requestPath.Substring(0, matchPath.Length), (string)context.Items["test.PathBase"]!);
Assert.Equal(string.Concat(basePath, requestPath.AsSpan(0, matchPath.Length)), (string)context.Items["test.PathBase"]!);
Assert.Equal(requestPath.Substring(matchPath.Length), context.Items["test.Path"]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Routing/src/Patterns/RoutePatternParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private string DebuggerToString()
}
else
{
return _template.Substring(0, _index) + "|" + _template.Substring(_index);
return string.Concat(_template.Substring(0, _index), "|", _template.Substring(_index));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think it wants you to do

Suggested change
return string.Concat(_template.Substring(0, _index), "|", _template.Substring(_index));
return string.Concat(_template.AsSpan(0, _index), "|", _template.AsSpan(_index));

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Identity/test/InMemory.Test/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private static async Task<TestServer> CreateServer(Action<IServiceCollection> co
}
else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
{
var isPersistent = bool.Parse(remainder.Value.Substring(1));
var isPersistent = bool.Parse(remainder.Value.AsSpan(1));
var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
res.StatusCode = result.Succeeded ? 200 : 500;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ private static void AppendBlockQuery(UriBuilder uriBuilder)
// and set the property with the combined string.
var queryToAppend = "comp=appendblock";
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
#if NETFRAMEWORK || NETSTANDARD
uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + queryToAppend;
#else
uriBuilder.Query = string.Concat(uriBuilder.Query.AsSpan(1), "&", queryToAppend);
#endif
else
uriBuilder.Query = queryToAppend;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public bool CheckRequestAcceptsCompression(HttpContext context)

if (slashPos >= 0)
{
var partialMimeType = mimeType!.Substring(0, slashPos.Value) + "/*";
var partialMimeType = string.Concat(mimeType!.AsSpan(0, slashPos.Value), "/*");
return ShouldCompressExact(partialMimeType);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/tools/RazorPageGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private string ProcessFileIncludes()
var includeFileName = cshtmlContent.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length));
Console.WriteLine(" Inlining file {0}", includeFileName);
var includeFileContent = File.ReadAllText(System.IO.Path.Combine(basePath, includeFileName));
cshtmlContent = cshtmlContent.Substring(0, startIndex) + includeFileContent + cshtmlContent.Substring(endIndex + endMatch.Length);
cshtmlContent = string.Concat(cshtmlContent.AsSpan(0, startIndex), includeFileContent, cshtmlContent.AsSpan(endIndex + endMatch.Length));
startIndex = startIndex + includeFileContent.Length;
}
return cshtmlContent;
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Mvc.Core/src/Routing/ViewEnginePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static string CombinePath(string first, string second)
}
else
{
result = first.Substring(0, index + 1) + second;
result = string.Concat(first.AsSpan(0, index + 1), second);
}

return ResolvePath(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static string JoinPath(string path1, string path2)
var hasLeadingSlash = path2.StartsWith("/", StringComparison.Ordinal);
if (hasLeadingSlash && hasTrailingSlash)
{
return path1 + path2.Substring(1);
return string.Concat(path1, path2.AsSpan(1));
}
else if (hasLeadingSlash || hasTrailingSlash)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static string CombinePath(string path1, string path2)
}
else if (path1.EndsWith("/", StringComparison.Ordinal) && path2.StartsWith("/", StringComparison.Ordinal))
{
return path1 + path2.Substring(1);
return string.Concat(path1, path2.AsSpan(1));
}

return path1 + "/" + path2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.AspNetCore.Authorization;

namespace CustomPolicyProvider
Expand All @@ -20,7 +21,7 @@ public int Age
{
get
{
if (int.TryParse(Policy.Substring(POLICY_PREFIX.Length), out var age))
if (int.TryParse(Policy.AsSpan(POLICY_PREFIX.Length), out var age))
{
return age;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Servers/Kestrel/samples/LargeResponseApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using System.Net;
using System.Text;
Expand All @@ -22,7 +23,7 @@ public void Configure(IApplicationBuilder app)
app.Run(async (context) =>
{
var path = context.Request.Path;
if (!path.HasValue || !int.TryParse(path.Value.Substring(1), out var numChunks))
if (!path.HasValue || !int.TryParse(path.Value.AsSpan(1), out var numChunks))
{
numChunks = _defaultNumChunks;
}
Expand All @@ -49,7 +50,7 @@ public static Task Main(string[] args)
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>();
})
})
.Build();

return host.RunAsync();
Expand Down
4 changes: 4 additions & 0 deletions src/Shared/CommandLineUtils/CommandLine/AnsiConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public void WriteLine(string message)
{
case 'm':
int value;
#if NETFRAMEWORK
if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value))
#else
if (int.TryParse(message.AsSpan(startIndex, endIndex - startIndex), out value))
#endif
{
switch (value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/src/AssemblyTestLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public IServiceProvider CreateLoggerServices(ITestOutputHelper output, string cl
throw new InvalidOperationException("Output file path could not be constructed due to max path length restrictions. Please shorten test assembly, class or method names.");
}

testName = testName.Substring(0, testNameLength / 2) + testName.Substring(testName.Length - testNameLength / 2, testNameLength / 2);
testName = string.Concat(testName.AsSpan(0, testNameLength / 2).ToString(), testName.AsSpan(testName.Length - testNameLength / 2, testNameLength / 2).ToString());

_globalLogger.LogWarning($"To prevent long paths test name was shortened to {testName}.");
}
Expand Down
4 changes: 4 additions & 0 deletions src/WebEncoders/src/Testing/HtmlTestEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
}

output.Write("HtmlEncode[[");
#if NETFRAMEWORK || NETSTANDARD
output.Write(value.Substring(startIndex, characterCount));
#else
output.Write(value.AsSpan(startIndex, characterCount));
#endif
output.Write("]]");
}

Expand Down
4 changes: 4 additions & 0 deletions src/WebEncoders/src/Testing/JavaScriptTestEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
}

output.Write("JavaScriptEncode[[");
#if NETFRAMEWORK || NETSTANDARD
output.Write(value.Substring(startIndex, characterCount));
#else
output.Write(value.AsSpan(startIndex, characterCount));
#endif
output.Write("]]");
}

Expand Down
4 changes: 4 additions & 0 deletions src/WebEncoders/src/Testing/UrlTestEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public override void Encode(TextWriter output, string value, int startIndex, int
}

output.Write("UrlEncode[[");
#if NETFRAMEWORK || NETSTANDARD
output.Write(value.Substring(startIndex, characterCount));
#else
output.Write(value.AsSpan(startIndex, characterCount));
#endif
output.Write("]]");
}

Expand Down