зеркало из https://github.com/dotnet/aspnetcore.git
Enable CA1821, CA1825-CA1834 (#33041)
* Enable CA1821, CA1825-CA1834 Contributes to https://github.com/dotnet/aspnetcore/issues/24055
This commit is contained in:
Родитель
b62acdfd5a
Коммит
e4f7bfb435
|
@ -91,9 +91,40 @@ dotnet_diagnostic.CA1802.severity = warning
|
|||
# CA1805: Do not initialize unnecessarily
|
||||
dotnet_diagnostic.CA1805.severity = warning
|
||||
|
||||
# CA1823: Remove empty Finalizers
|
||||
dotnet_diagnostic.CA1821.severity = warning
|
||||
|
||||
# CA1823: Avoid unused private fields
|
||||
dotnet_diagnostic.CA1823.severity = warning
|
||||
|
||||
# CA1823: Avoid zero-length array allocations
|
||||
dotnet_diagnostic.CA1825.severity = warning
|
||||
|
||||
# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
|
||||
dotnet_diagnostic.CA1826.severity = warning
|
||||
|
||||
# CA1827: Do not use Count() or LongCount() when Any() can be used
|
||||
dotnet_diagnostic.CA1827.severity = warning
|
||||
|
||||
# CA1828: Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used
|
||||
dotnet_diagnostic.CA1828.severity = warning
|
||||
|
||||
# CA1829: Use Length/Count property instead of Count() when available
|
||||
dotnet_diagnostic.CA1829.severity = warning
|
||||
|
||||
# CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder
|
||||
dotnet_diagnostic.CA1830.severity = warning
|
||||
|
||||
# CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
|
||||
# CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
|
||||
# CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
|
||||
dotnet_diagnostic.CA1831.severity = warning
|
||||
dotnet_diagnostic.CA1832.severity = warning
|
||||
dotnet_diagnostic.CA1833.severity = warning
|
||||
|
||||
# CA1834: Consider using 'StringBuilder.Append(char)' when applicable
|
||||
dotnet_diagnostic.CA1834.severity = warning
|
||||
|
||||
# CA2012: Use ValueTask correctly
|
||||
dotnet_diagnostic.CA2012.severity = warning
|
||||
|
||||
|
@ -110,5 +141,15 @@ dotnet_diagnostic.CA1507.severity = suggestion
|
|||
dotnet_diagnostic.CA1802.severity = suggestion
|
||||
# CA1805: Do not initialize unnecessarily
|
||||
dotnet_diagnostic.CA1805.severity = suggestion
|
||||
# CA1823: Avoid zero-length array allocations
|
||||
dotnet_diagnostic.CA1825.severity = suggestion
|
||||
# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
|
||||
dotnet_diagnostic.CA1826.severity = suggestion
|
||||
# CA1827: Do not use Count() or LongCount() when Any() can be used
|
||||
dotnet_diagnostic.CA1827.severity = suggestion
|
||||
# CA1829: Use Length/Count property instead of Count() when available
|
||||
dotnet_diagnostic.CA1829.severity = suggestion
|
||||
# CA1834: Consider using 'StringBuilder.Append(char)' when applicable
|
||||
dotnet_diagnostic.CA1834.severity = suggestion
|
||||
# CA2012: Use ValueTask correctly
|
||||
dotnet_diagnostic.CA2012.severity = suggestion
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace PackageBaselineGenerator
|
|||
foreach (var group in reader.NuspecReader.GetDependencyGroups())
|
||||
{
|
||||
// Don't bother generating empty ItemGroup elements.
|
||||
if (group.Packages.Count() == 0)
|
||||
if (!group.Packages.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace TestHelper
|
|||
/// <param name="expectedResults">Diagnostic Results that should have appeared in the code</param>
|
||||
private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expectedResults)
|
||||
{
|
||||
int expectedCount = expectedResults.Count();
|
||||
int expectedCount = expectedResults.Length;
|
||||
int actualCount = actualResults.Count();
|
||||
|
||||
if (expectedCount != actualCount)
|
||||
|
|
|
@ -119,9 +119,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Services
|
|||
logBuilder.Append(GetLogLevelString(logLevel));
|
||||
logBuilder.Append(_loglevelPadding);
|
||||
logBuilder.Append(logName);
|
||||
logBuilder.Append("[");
|
||||
logBuilder.Append('[');
|
||||
logBuilder.Append(eventId);
|
||||
logBuilder.Append("]");
|
||||
logBuilder.Append(']');
|
||||
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
|
|
|
@ -292,9 +292,9 @@ namespace Microsoft.AspNetCore.Components.WebView
|
|||
|
||||
private static void AppendKeyValuePair(StringBuilder builder, string key, string? value, bool first)
|
||||
{
|
||||
builder.Append(first ? "?" : "&");
|
||||
builder.Append(first ? '?' : '&');
|
||||
builder.Append(UrlEncoder.Default.Encode(key));
|
||||
builder.Append("=");
|
||||
builder.Append('=');
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
builder.Append(UrlEncoder.Default.Encode(value));
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace Microsoft.Extensions.FileProviders.Embedded.Manifest
|
|||
|
||||
private static string EnsureText(XElement element)
|
||||
{
|
||||
if (element.Elements().Count() == 0 &&
|
||||
if (!element.Elements().Any() &&
|
||||
!element.IsEmpty &&
|
||||
element.Nodes().Count() == 1 &&
|
||||
element.FirstNode?.NodeType == XmlNodeType.Text)
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
var header = new StringBuilder();
|
||||
|
||||
header.Append(_name.AsSpan());
|
||||
header.Append("=");
|
||||
header.Append('=');
|
||||
header.Append(_value.AsSpan());
|
||||
|
||||
return header.ToString();
|
||||
|
|
|
@ -329,7 +329,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
public void AppendToStringBuilder(StringBuilder builder)
|
||||
{
|
||||
builder.Append(_name.AsSpan());
|
||||
builder.Append("=");
|
||||
builder.Append('=');
|
||||
builder.Append(_value.AsSpan());
|
||||
|
||||
if (Expires.HasValue)
|
||||
|
@ -388,7 +388,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
builder.Append(name.AsSpan());
|
||||
if (value != null)
|
||||
{
|
||||
builder.Append("=");
|
||||
builder.Append('=');
|
||||
builder.Append(value.AsSpan());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -286,9 +286,9 @@ namespace Microsoft.AspNetCore.Http
|
|||
|
||||
private static void AppendKeyValuePair(StringBuilder builder, string key, string? value, bool first)
|
||||
{
|
||||
builder.Append(first ? "?" : "&");
|
||||
builder.Append(first ? '?' : '&');
|
||||
builder.Append(UrlEncoder.Default.Encode(key));
|
||||
builder.Append("=");
|
||||
builder.Append('=');
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
builder.Append(UrlEncoder.Default.Encode(value));
|
||||
|
|
|
@ -480,14 +480,14 @@ namespace Microsoft.AspNetCore.Routing
|
|||
|
||||
foreach (var kvp in values.OrderBy(kvp => kvp.Key))
|
||||
{
|
||||
builder.Append("\"");
|
||||
builder.Append('"');
|
||||
builder.Append(kvp.Key);
|
||||
builder.Append("\"");
|
||||
builder.Append(":");
|
||||
builder.Append(" ");
|
||||
builder.Append("\"");
|
||||
builder.Append('"');
|
||||
builder.Append(':');
|
||||
builder.Append(' ');
|
||||
builder.Append('"');
|
||||
builder.Append(kvp.Value);
|
||||
builder.Append("\"");
|
||||
builder.Append('"');
|
||||
builder.Append(", ");
|
||||
}
|
||||
|
||||
|
|
|
@ -80,14 +80,14 @@ namespace Microsoft.AspNetCore.Routing.Patterns
|
|||
internal override string DebuggerToString()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("{");
|
||||
builder.Append('{');
|
||||
|
||||
if (IsCatchAll)
|
||||
{
|
||||
builder.Append("*");
|
||||
builder.Append('*');
|
||||
if (!EncodeSlashes)
|
||||
{
|
||||
builder.Append("*");
|
||||
builder.Append('*');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,22 +95,22 @@ namespace Microsoft.AspNetCore.Routing.Patterns
|
|||
|
||||
foreach (var constraint in ParameterPolicies)
|
||||
{
|
||||
builder.Append(":");
|
||||
builder.Append(':');
|
||||
builder.Append(constraint.ParameterPolicy);
|
||||
}
|
||||
|
||||
if (Default != null)
|
||||
{
|
||||
builder.Append("=");
|
||||
builder.Append('=');
|
||||
builder.Append(Default);
|
||||
}
|
||||
|
||||
if (IsOptional)
|
||||
{
|
||||
builder.Append("?");
|
||||
builder.Append('?');
|
||||
}
|
||||
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
|
|||
{
|
||||
matchesSb.Insert(0, branch);
|
||||
}
|
||||
sb.Append(matchesSb.ToString());
|
||||
sb.Append(matchesSb);
|
||||
sb.Append(" (Matches: ");
|
||||
sb.AppendJoin(", ", node.Matches.Select(m => m.Entry.RouteTemplate.TemplateText));
|
||||
sb.AppendLine(")");
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
{
|
||||
if (_path.Length != 0)
|
||||
{
|
||||
_path.Append("/");
|
||||
_path.Append('/');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
// This prevents the leading slash from PathString segments from being encoded.
|
||||
if (_path.Length == 0 && value.Length > 0 && value[0] == '/')
|
||||
{
|
||||
_path.Append("/");
|
||||
_path.Append('/');
|
||||
EncodeValue(value, 1, value.Length - 1, encodeSlashes);
|
||||
}
|
||||
else
|
||||
|
@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Routing
|
|||
while ((end = value.IndexOf('/', start, characterCount)) >= 0)
|
||||
{
|
||||
_urlEncoder.Encode(PathWriter, value, start, end - start);
|
||||
_path.Append("/");
|
||||
_path.Append('/');
|
||||
|
||||
start = end + 1;
|
||||
characterCount = length - start;
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace Swaggatherer
|
|||
// We don't yet handle complex segments
|
||||
var part = template.Segments[i].Parts[0];
|
||||
|
||||
url.Append("/");
|
||||
url.Append('/');
|
||||
url.Append(part.IsLiteral ? part.Text : GenerateParameterValue(part));
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
input = input.TrimEnd('=').ToUpperInvariant();
|
||||
if (input.Length == 0)
|
||||
{
|
||||
return new byte[0];
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
var output = new byte[input.Length * 5 / 8];
|
||||
|
|
|
@ -1826,7 +1826,7 @@ namespace Microsoft.AspNetCore.Identity.Test
|
|||
await manager.ConfirmEmailAsync(user, token);
|
||||
factors = await manager.GetValidTwoFactorProvidersAsync(user);
|
||||
Assert.NotNull(factors);
|
||||
Assert.Equal(2, factors.Count());
|
||||
Assert.Equal(2, factors.Count);
|
||||
IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user, null));
|
||||
factors = await manager.GetValidTwoFactorProvidersAsync(user);
|
||||
Assert.NotNull(factors);
|
||||
|
@ -1835,7 +1835,7 @@ namespace Microsoft.AspNetCore.Identity.Test
|
|||
IdentityResultAssert.IsSuccess(await manager.ResetAuthenticatorKeyAsync(user));
|
||||
factors = await manager.GetValidTwoFactorProvidersAsync(user);
|
||||
Assert.NotNull(factors);
|
||||
Assert.Equal(2, factors.Count());
|
||||
Assert.Equal(2, factors.Count);
|
||||
Assert.Equal("Authenticator", factors[1]);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,12 +182,12 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Manage.Internal
|
|||
int currentPosition = 0;
|
||||
while (currentPosition + 4 < unformattedKey.Length)
|
||||
{
|
||||
result.Append(unformattedKey.Substring(currentPosition, 4)).Append(" ");
|
||||
result.Append(unformattedKey.AsSpan(currentPosition, 4)).Append(' ');
|
||||
currentPosition += 4;
|
||||
}
|
||||
if (currentPosition < unformattedKey.Length)
|
||||
{
|
||||
result.Append(unformattedKey.Substring(currentPosition));
|
||||
result.Append(unformattedKey.AsSpan(currentPosition));
|
||||
}
|
||||
|
||||
return result.ToString().ToLowerInvariant();
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Identity.InMemory
|
|||
public class InMemoryStore<TUser, TRole> :
|
||||
InMemoryUserStore<TUser>,
|
||||
IUserRoleStore<TUser>,
|
||||
IQueryableRoleStore<TRole>,
|
||||
IQueryableRoleStore<TRole>,
|
||||
IRoleClaimStore<TRole>
|
||||
where TRole : PocoRole
|
||||
where TUser : PocoUser
|
||||
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Identity.InMemory
|
|||
{
|
||||
return Task.FromResult<IList<TUser>>(new List<TUser>());
|
||||
}
|
||||
return Task.FromResult<IList<TUser>>(Users.Where(u => (u.Roles.Where(x => x.RoleId == role.Id).Count() > 0)).Select(x => x).ToList());
|
||||
return Task.FromResult<IList<TUser>>(Users.Where(u => (u.Roles.Where(x => x.RoleId == role.Id).Any())).Select(x => x).ToList());
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, TRole> _roles = new Dictionary<string, TRole>();
|
||||
|
|
|
@ -161,16 +161,16 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
|||
builder.Append(SupportsCredentials);
|
||||
builder.Append(", Origins: {");
|
||||
builder.AppendJoin(",", Origins);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
builder.Append(", Methods: {");
|
||||
builder.AppendJoin(",", Methods);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
builder.Append(", Headers: {");
|
||||
builder.AppendJoin(",", Headers);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
builder.Append(", ExposedHeaders: {");
|
||||
builder.AppendJoin(",", ExposedHeaders);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
|
|
|
@ -93,13 +93,13 @@ namespace Microsoft.AspNetCore.Cors.Infrastructure
|
|||
builder.Append(AllowedOrigin);
|
||||
builder.Append(", AllowExposedHeaders: {");
|
||||
builder.AppendJoin(",", AllowedExposedHeaders);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
builder.Append(", AllowHeaders: {");
|
||||
builder.AppendJoin(",", AllowedHeaders);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
builder.Append(", AllowMethods: {");
|
||||
builder.AppendJoin(",", AllowedMethods);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
|
|||
var contextType = _localDiagnostic.Value!.ContextType;
|
||||
var details = await httpContext.GetContextDetailsAsync(contextType!, _logger);
|
||||
|
||||
if (details != null && (details.PendingModelChanges || details.PendingMigrations.Count() > 0))
|
||||
if (details != null && (details.PendingModelChanges || details.PendingMigrations.Any()))
|
||||
{
|
||||
var page = new DatabaseErrorPage
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
|
|||
// Arrange
|
||||
var services = CreateServices(async (c, ct) =>
|
||||
{
|
||||
return 0 < await c.Blogs.CountAsync();
|
||||
return await c.Blogs.AnyAsync();
|
||||
});
|
||||
|
||||
using (var scope = services.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
|
@ -66,7 +66,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
|
|||
// Arrange
|
||||
var services = CreateServices(async (c, ct) =>
|
||||
{
|
||||
return 0 < await c.Blogs.CountAsync();
|
||||
return await c.Blogs.AnyAsync();
|
||||
}, failureStatus: HealthStatus.Degraded);
|
||||
|
||||
using (var scope = services.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
|
@ -88,7 +88,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
|
|||
// Arrange
|
||||
var services = CreateServices(async (c, ct) =>
|
||||
{
|
||||
return 0 < await c.Blogs.CountAsync();
|
||||
return await c.Blogs.AnyAsync();
|
||||
}, failureStatus: HealthStatus.Unhealthy);
|
||||
|
||||
using (var scope = services.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
|
@ -110,7 +110,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
|
|||
// Arrange
|
||||
var services = CreateServices(async (c, ct) =>
|
||||
{
|
||||
return 0 < await c.Blogs.CountAsync();
|
||||
return await c.Blogs.AnyAsync();
|
||||
}, failureStatus: null);
|
||||
|
||||
using (var scope = services.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Session
|
|||
|
||||
public ICollection<EncodedKey> Keys { get; } = Array.Empty<EncodedKey>();
|
||||
|
||||
public ICollection<byte[]> Values { get; } = new byte[0][];
|
||||
public ICollection<byte[]> Values { get; } = Array.Empty<byte[]>();
|
||||
|
||||
public void Clear() { }
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
/// <summary>
|
||||
/// A <see cref="ValueProviderResult"/> that represents a lack of data.
|
||||
/// </summary>
|
||||
public static ValueProviderResult None = new ValueProviderResult(new string[0]);
|
||||
public static ValueProviderResult None = new ValueProviderResult(Array.Empty<string>());
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
|
||||
|
|
|
@ -766,7 +766,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var routeKeys = action.RouteValues.Keys.ToArray();
|
||||
var routeValues = action.RouteValues.Values.ToArray();
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("{");
|
||||
stringBuilder.Append('{');
|
||||
for (var i = 0; i < routeValues.Length; i++)
|
||||
{
|
||||
if (i == routeValues.Length - 1)
|
||||
|
@ -778,7 +778,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
stringBuilder.Append($"{routeKeys[i]} = \"{routeValues[i]}\", ");
|
||||
}
|
||||
}
|
||||
stringBuilder.Append("}");
|
||||
stringBuilder.Append('}');
|
||||
|
||||
if (action.RouteValues.TryGetValue("page", out var page) && page != null)
|
||||
{
|
||||
|
|
|
@ -306,7 +306,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
|
|||
builder
|
||||
.Append(CacheKeyTokenSeparator)
|
||||
.Append(collectionName)
|
||||
.Append("(");
|
||||
.Append('(');
|
||||
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
{
|
||||
|
@ -323,7 +323,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
|
|||
.Append(item.Value);
|
||||
}
|
||||
|
||||
builder.Append(")");
|
||||
builder.Append(')');
|
||||
}
|
||||
|
||||
private static void CombineCollectionHashCode(
|
||||
|
|
|
@ -170,9 +170,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
|
||||
private void WriteTargetElementString(CodeWriter writer, TagHelperDescriptor tagHelper)
|
||||
{
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count() == 1);
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count == 1);
|
||||
|
||||
var rule = tagHelper.TagMatchingRules.First();
|
||||
var rule = tagHelper.TagMatchingRules[0];
|
||||
|
||||
writer.Write("[")
|
||||
.WriteStartMethodInvocation(HtmlTargetElementAttributeTypeName)
|
||||
|
|
|
@ -170,9 +170,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X
|
|||
|
||||
private void WriteTargetElementString(CodeWriter writer, TagHelperDescriptor tagHelper)
|
||||
{
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count() == 1);
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count == 1);
|
||||
|
||||
var rule = tagHelper.TagMatchingRules.First();
|
||||
var rule = tagHelper.TagMatchingRules[0];
|
||||
|
||||
writer.Write("[")
|
||||
.WriteStartMethodInvocation(HtmlTargetElementAttributeTypeName)
|
||||
|
|
|
@ -170,9 +170,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
|
||||
private void WriteTargetElementString(CodeWriter writer, TagHelperDescriptor tagHelper)
|
||||
{
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count() == 1);
|
||||
Debug.Assert(tagHelper.TagMatchingRules.Count == 1);
|
||||
|
||||
var rule = tagHelper.TagMatchingRules.First();
|
||||
var rule = tagHelper.TagMatchingRules[0];
|
||||
|
||||
writer.Write("[")
|
||||
.WriteStartMethodInvocation(HtmlTargetElementAttributeTypeName)
|
||||
|
|
|
@ -775,7 +775,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
|
||||
private static IntermediateToken GetAttributeContent(IntermediateNode node)
|
||||
{
|
||||
var template = node.FindDescendantNodes<TemplateIntermediateNode>().FirstOrDefault();
|
||||
var nodes = node.FindDescendantNodes<TemplateIntermediateNode>();
|
||||
var template = nodes.Count > 0 ? nodes[0] : default;
|
||||
if (template != null)
|
||||
{
|
||||
// See comments in TemplateDiagnosticPass
|
||||
|
|
|
@ -242,7 +242,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
|
||||
private static IReadOnlyList<IntermediateToken> GetAttributeContent(IntermediateNode node)
|
||||
{
|
||||
var template = node.FindDescendantNodes<TemplateIntermediateNode>().FirstOrDefault();
|
||||
var nodes = node.FindDescendantNodes<TemplateIntermediateNode>();
|
||||
var template = nodes.Count > 0 ? nodes[0] : default;
|
||||
if (template != null)
|
||||
{
|
||||
// See comments in TemplateDiagnosticPass
|
||||
|
|
|
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
// Treat node with errors as non-HTML
|
||||
_foundNonHtml = true;
|
||||
}
|
||||
|
||||
|
||||
// Visit Children
|
||||
base.VisitDefault(node);
|
||||
|
||||
|
@ -277,7 +277,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
var isVoid = Legacy.ParserHelpers.VoidElements.Contains(node.TagName);
|
||||
var hasBodyContent = node.Body.Any();
|
||||
|
||||
Builder.Append("<");
|
||||
Builder.Append('<');
|
||||
Builder.Append(node.TagName);
|
||||
|
||||
foreach (var attribute in node.Attributes)
|
||||
|
@ -290,7 +290,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
if (!hasBodyContent && isVoid)
|
||||
{
|
||||
// void
|
||||
Builder.Append(">");
|
||||
Builder.Append('>');
|
||||
return;
|
||||
}
|
||||
else if (!hasBodyContent)
|
||||
|
@ -299,12 +299,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
// add a close tag
|
||||
Builder.Append("></");
|
||||
Builder.Append(node.TagName);
|
||||
Builder.Append(">");
|
||||
Builder.Append('>');
|
||||
return;
|
||||
}
|
||||
|
||||
// start/end tag with body.
|
||||
Builder.Append(">");
|
||||
Builder.Append('>');
|
||||
|
||||
foreach (var item in node.Body)
|
||||
{
|
||||
|
@ -313,12 +313,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
|
||||
Builder.Append("</");
|
||||
Builder.Append(node.TagName);
|
||||
Builder.Append(">");
|
||||
Builder.Append('>');
|
||||
}
|
||||
|
||||
public override void VisitHtmlAttribute(HtmlAttributeIntermediateNode node)
|
||||
{
|
||||
Builder.Append(" ");
|
||||
Builder.Append(' ');
|
||||
Builder.Append(node.AttributeName);
|
||||
|
||||
if (node.Children.Count == 0)
|
||||
|
@ -332,7 +332,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
// Visit Children
|
||||
base.VisitDefault(node);
|
||||
|
||||
Builder.Append("\"");
|
||||
Builder.Append('"');
|
||||
}
|
||||
|
||||
public override void VisitHtmlAttributeValue(HtmlAttributeValueIntermediateNode node)
|
||||
|
|
|
@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_builder.Add(new DirectiveTokenIntermediateNode()
|
||||
{
|
||||
Content = addTagHelperChunkGenerator.LookupText,
|
||||
DirectiveToken = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Tokens.First(),
|
||||
DirectiveToken = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Tokens[0],
|
||||
Source = BuildSourceSpanFromNode(node),
|
||||
});
|
||||
|
||||
|
@ -385,7 +385,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_builder.Add(new DirectiveTokenIntermediateNode()
|
||||
{
|
||||
Content = removeTagHelperChunkGenerator.LookupText,
|
||||
DirectiveToken = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Tokens.First(),
|
||||
DirectiveToken = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Tokens[0],
|
||||
Source = BuildSourceSpanFromNode(node),
|
||||
});
|
||||
|
||||
|
@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
_builder.Add(new DirectiveTokenIntermediateNode()
|
||||
{
|
||||
Content = tagHelperPrefixChunkGenerator.Prefix,
|
||||
DirectiveToken = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Tokens.First(),
|
||||
DirectiveToken = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Tokens[0],
|
||||
Source = BuildSourceSpanFromNode(node),
|
||||
});
|
||||
|
||||
|
@ -1019,7 +1019,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
IReadOnlyList<SyntaxNode> children = node.ChildNodes();
|
||||
var position = node.Position;
|
||||
if (children.FirstOrDefault() is MarkupBlockSyntax markupBlock &&
|
||||
if (children.Count > 0 &&
|
||||
children[0] is MarkupBlockSyntax markupBlock &&
|
||||
markupBlock.Children.Count == 2 &&
|
||||
markupBlock.Children[0] is MarkupTextLiteralSyntax &&
|
||||
markupBlock.Children[1] is MarkupEphemeralTextLiteralSyntax)
|
||||
|
@ -1970,7 +1971,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
IReadOnlyList<SyntaxNode> children = node.ChildNodes();
|
||||
var position = node.Position;
|
||||
if (children.FirstOrDefault() is MarkupBlockSyntax markupBlock &&
|
||||
if (children.Count > 0 &&
|
||||
children[0] is MarkupBlockSyntax markupBlock &&
|
||||
markupBlock.Children.Count == 2 &&
|
||||
markupBlock.Children[0] is MarkupTextLiteralSyntax &&
|
||||
markupBlock.Children[1] is MarkupEphemeralTextLiteralSyntax)
|
||||
|
|
|
@ -46,11 +46,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
|||
for (var i = 0; i <parameter.Modifiers.Count; i++)
|
||||
{
|
||||
builder.Append(parameter.Modifiers[i]);
|
||||
builder.Append(" ");
|
||||
builder.Append(' ');
|
||||
}
|
||||
|
||||
builder.Append(parameter.TypeName);
|
||||
builder.Append(" ");
|
||||
builder.Append(' ');
|
||||
|
||||
builder.Append(parameter.ParameterName);
|
||||
|
||||
|
|
|
@ -64,20 +64,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var builder = new StringBuilder("AddTagHelper:{");
|
||||
builder.Append(LookupText);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(DirectiveText);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(TypePattern);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(AssemblyName);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
|
||||
if (Diagnostics.Count > 0)
|
||||
{
|
||||
builder.Append(" [");
|
||||
var ids = string.Join(", ", Diagnostics.Select(diagnostic => $"{diagnostic.Id}{diagnostic.Span}"));
|
||||
builder.Append(ids);
|
||||
builder.Append("]");
|
||||
builder.Append(']');
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
|
|
|
@ -46,10 +46,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
builder.Description = Resources.TagHelperPrefixDirective_Description;
|
||||
});
|
||||
|
||||
internal static readonly IEnumerable<DirectiveDescriptor> DefaultDirectiveDescriptors = new DirectiveDescriptor[]
|
||||
{
|
||||
};
|
||||
|
||||
internal static ISet<string> DefaultKeywords = new HashSet<string>()
|
||||
{
|
||||
SyntaxConstants.CSharp.TagHelperPrefixKeyword,
|
||||
|
@ -912,11 +908,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
|
||||
private void SetupDirectiveParsers(IEnumerable<DirectiveDescriptor> directiveDescriptors)
|
||||
{
|
||||
var allDirectives = directiveDescriptors.Concat(DefaultDirectiveDescriptors).ToList();
|
||||
|
||||
for (var i = 0; i < allDirectives.Count; i++)
|
||||
foreach (var directiveDescriptor in directiveDescriptors)
|
||||
{
|
||||
var directiveDescriptor = allDirectives[i];
|
||||
CurrentKeywords.Add(directiveDescriptor.Directive);
|
||||
MapDirectives((builder, transition) => ParseExtensibleDirective(builder, transition, directiveDescriptor), directiveDescriptor.Directive);
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var builder = new StringBuilder("DirectiveToken {");
|
||||
builder.Append(Descriptor.Name);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(Descriptor.Kind);
|
||||
builder.Append(";Opt:");
|
||||
builder.Append(Descriptor.Optional);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
|
|
@ -64,20 +64,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var builder = new StringBuilder("RemoveTagHelper:{");
|
||||
builder.Append(LookupText);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(DirectiveText);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(TypePattern);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(AssemblyName);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
|
||||
if (Diagnostics.Count > 0)
|
||||
{
|
||||
builder.Append(" [");
|
||||
var ids = string.Join(", ", Diagnostics.Select(diagnostic => $"{diagnostic.Id}{diagnostic.Span}"));
|
||||
builder.Append(ids);
|
||||
builder.Append("]");
|
||||
builder.Append(']');
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
// Internal for testing.
|
||||
// Null characters are invalid markup for HTML attribute values.
|
||||
internal const string InvalidAttributeValueMarker = "\0";
|
||||
internal const char InvalidAttributeValueMarker = '\0';
|
||||
|
||||
private readonly RazorSourceDocument _source;
|
||||
private readonly string _tagHelperPrefix;
|
||||
|
@ -759,7 +759,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
if (AllowedChildren != null && _prefixedAllowedChildren == null)
|
||||
{
|
||||
Debug.Assert(Info.BindingResult.Descriptors.Count() >= 1);
|
||||
Debug.Assert(Info.BindingResult.Descriptors.Any());
|
||||
|
||||
_prefixedAllowedChildren = AllowedChildren.Select(allowedChild => _tagHelperPrefix + allowedChild).ToList();
|
||||
}
|
||||
|
|
|
@ -49,19 +49,19 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
var builder = new StringBuilder("TagHelperPrefix:{");
|
||||
builder.Append(Prefix);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(DirectiveText);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
|
||||
if (Diagnostics.Count > 0)
|
||||
{
|
||||
builder.Append(" [");
|
||||
var ids = string.Join(", ", Diagnostics.Select(diagnostic => $"{diagnostic.Id}{diagnostic.Span}"));
|
||||
builder.Append(ids);
|
||||
builder.Append("]");
|
||||
builder.Append(']');
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
public abstract class RazorDiagnostic : IEquatable<RazorDiagnostic>, IFormattable
|
||||
{
|
||||
internal static readonly RazorDiagnostic[] EmptyArray = new RazorDiagnostic[0];
|
||||
internal static readonly object[] EmptyArgs = new object[0];
|
||||
internal static readonly RazorDiagnostic[] EmptyArray = Array.Empty<RazorDiagnostic>();
|
||||
internal static readonly object[] EmptyArgs = Array.Empty<object>();
|
||||
|
||||
public abstract string Id { get; }
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
internal const int LargeObjectHeapLimitInChars = 40 * 1024; // 40K Unicode chars is 80KB which is less than the large object heap limit.
|
||||
|
||||
internal static readonly RazorSourceDocument[] EmptyArray = new RazorSourceDocument[0];
|
||||
internal static readonly RazorSourceDocument[] EmptyArray = Array.Empty<RazorSourceDocument>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the encoding of the text in the original source document.
|
||||
|
|
|
@ -197,11 +197,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Syntax
|
|||
|
||||
var builder = new StringBuilder("Directive:{");
|
||||
builder.Append(node.DirectiveDescriptor.Directive);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(node.DirectiveDescriptor.Kind);
|
||||
builder.Append(";");
|
||||
builder.Append(';');
|
||||
builder.Append(node.DirectiveDescriptor.Usage);
|
||||
builder.Append("}");
|
||||
builder.Append('}');
|
||||
|
||||
var diagnostics = node.GetDiagnostics();
|
||||
if (diagnostics.Length > 0)
|
||||
|
@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Syntax
|
|||
builder.Append(" [");
|
||||
var ids = string.Join(", ", diagnostics.Select(diagnostic => $"{diagnostic.Id}{diagnostic.Span}"));
|
||||
builder.Append(ids);
|
||||
builder.Append("]");
|
||||
builder.Append(']');
|
||||
}
|
||||
|
||||
WriteSeparator();
|
||||
|
|
|
@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
var formTagHelper = Assert.Single(tagHelperNodes);
|
||||
Assert.Equal("form", formTagHelper.TagHelperInfo.TagName);
|
||||
Assert.Equal(2, formTagHelper.TagHelperInfo.BindingResult.Mappings[descriptor].Count());
|
||||
Assert.Equal(2, formTagHelper.TagHelperInfo.BindingResult.Mappings[descriptor].Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -398,7 +398,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
var formTagHelper = Assert.Single(tagHelperNodes);
|
||||
Assert.Equal("form", formTagHelper.TagHelperInfo.TagName);
|
||||
Assert.Equal(2, formTagHelper.TagHelperInfo.BindingResult.Mappings[descriptor].Count());
|
||||
Assert.Equal(2, formTagHelper.TagHelperInfo.BindingResult.Mappings[descriptor].Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -653,7 +653,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
},
|
||||
{
|
||||
$@"
|
||||
@tagHelperPrefix
|
||||
@tagHelperPrefix
|
||||
@addTagHelper Microsoft.AspNetCore.Razor.TagHelpers.ValidPlain*, {AssemblyA}
|
||||
@addTagHelper Microsoft.AspNetCore.Razor.TagHelpers.ValidInherited*, {AssemblyA}",
|
||||
null
|
||||
|
@ -858,7 +858,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
visitor.Visit(syntaxTree.Root);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected.Count(), visitor.Matches.Count());
|
||||
Assert.Equal(expected.Length, visitor.Matches.Count);
|
||||
|
||||
foreach (var expectedDescriptor in expected)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Func<string, string, KeyValuePair<string, string>> kvp =
|
||||
(key, value) => new KeyValuePair<string, string>(key, value);
|
||||
var empty = Enumerable.Empty<KeyValuePair<string, string>>();
|
||||
var csharp = TagHelperParseTreeRewriter.Rewriter.InvalidAttributeValueMarker;
|
||||
var csharp = TagHelperParseTreeRewriter.Rewriter.InvalidAttributeValueMarker.ToString();
|
||||
|
||||
// documentContent, expectedPairs
|
||||
return new TheoryData<string, IEnumerable<KeyValuePair<string, string>>>
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var hashes = new HashSet<int>(tagHelpers.Select(t => t.GetHashCode()));
|
||||
|
||||
// Assert
|
||||
Assert.Equal(hashes.Count(), tagHelpers.Count);
|
||||
Assert.Equal(hashes.Count, tagHelpers.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
// Assert
|
||||
// Only 1 batch of taghelpers should remain after we filter by hash
|
||||
Assert.Equal(hashes.Count(), tagHelpersPerBatch);
|
||||
Assert.Equal(hashes.Count, tagHelpersPerBatch);
|
||||
}
|
||||
|
||||
private static TagHelperDescriptor CreateTagHelperDescriptor(
|
||||
|
|
|
@ -288,7 +288,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
builder.TagMatchingRule(r =>
|
||||
{
|
||||
r.TagName = attribute.Name;
|
||||
r.ParentTag = component.TagMatchingRules.First().TagName;
|
||||
r.ParentTag = component.TagMatchingRules[0].TagName;
|
||||
});
|
||||
|
||||
if (attribute.IsParameterizedChildContentProperty())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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;
|
||||
|
|
|
@ -2087,7 +2087,7 @@ namespace RazorSyntaxGenerator
|
|||
|
||||
var minimalFactoryfields = new HashSet<Field>(DetermineMinimalFactoryFields(nd));
|
||||
|
||||
if (withStringNames && minimalFactoryfields.Count(f => IsRequiredFactoryField(nd, f) && CanAutoConvertFromString(f)) == 0)
|
||||
if (withStringNames && !minimalFactoryfields.Any(f => IsRequiredFactoryField(nd, f) && CanAutoConvertFromString(f)))
|
||||
return; // no string-name overload necessary
|
||||
|
||||
WriteLine();
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate
|
|||
var ntAuthType = secAssembly.GetType("System.Net.NTAuthentication", throwOnError: true)!;
|
||||
_constructor = ntAuthType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First();
|
||||
_getOutgoingBlob = ntAuthType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(info =>
|
||||
info.Name.Equals("GetOutgoingBlob") && info.GetParameters().Count() == 3).Single();
|
||||
info.Name.Equals("GetOutgoingBlob") && info.GetParameters().Length == 3).Single();
|
||||
_isCompleted = ntAuthType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(info =>
|
||||
info.Name.Equals("get_IsCompleted")).Single();
|
||||
_protocol = ntAuthType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Where(info =>
|
||||
|
|
|
@ -285,7 +285,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
var response = await server.CreateClient().GetAsync("https://example.com/");
|
||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task VerifyValidationFailureCanBeHandled()
|
||||
{
|
||||
|
@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.SubjectName.Name))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.X500DistinguishedName);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.SubjectName.Name, actual.First().Value);
|
||||
|
@ -499,7 +499,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.SerialNumber))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.SerialNumber);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.SerialNumber, actual.First().Value);
|
||||
|
@ -509,7 +509,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.DnsName, false)))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.Dns);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.DnsName, false), actual.First().Value);
|
||||
|
@ -519,7 +519,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.EmailName, false)))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.Email);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.EmailName, false), actual.First().Value);
|
||||
|
@ -529,7 +529,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.SimpleName, false)))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.Name);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.SimpleName, false), actual.First().Value);
|
||||
|
@ -539,7 +539,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.UpnName, false)))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.Upn);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.UpnName, false), actual.First().Value);
|
||||
|
@ -549,7 +549,7 @@ namespace Microsoft.AspNetCore.Authentication.Certificate.Test
|
|||
if (!string.IsNullOrEmpty(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.UrlName, false)))
|
||||
{
|
||||
actual = responseAsXml.Elements("claim").Where(claim => claim.Attribute("Type").Value == ClaimTypes.Uri);
|
||||
if (actual.Count() > 0)
|
||||
if (actual.Any())
|
||||
{
|
||||
Assert.Single(actual);
|
||||
Assert.Equal(Certificates.SelfSignedValidWithNoEku.GetNameInfo(X509NameType.UrlName, false), actual.First().Value);
|
||||
|
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
|||
else if (!hasData && !addTrailers)
|
||||
{
|
||||
// No data
|
||||
dataChunks = new HttpApiTypes.HTTP_DATA_CHUNK[0];
|
||||
dataChunks = Array.Empty<HttpApiTypes.HTTP_DATA_CHUNK>();
|
||||
return pins;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append(method);
|
||||
builder.Append("[");
|
||||
builder.Append('[');
|
||||
builder.Append(buffer.Length);
|
||||
builder.Append("]");
|
||||
builder.Append(']');
|
||||
|
||||
if (buffer.Length > 0)
|
||||
{
|
||||
|
@ -163,12 +163,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
builder.Append(buffer[i].ToString("X2", CultureInfo.InvariantCulture));
|
||||
builder.Append(" ");
|
||||
builder.Append(' ');
|
||||
|
||||
var bufferChar = (char)buffer[i];
|
||||
if (char.IsControl(bufferChar))
|
||||
{
|
||||
charBuilder.Append(".");
|
||||
charBuilder.Append('.');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
if ((i + 1) % 16 == 0)
|
||||
{
|
||||
builder.Append(" ");
|
||||
builder.Append(charBuilder.ToString());
|
||||
builder.Append(charBuilder);
|
||||
if (i != buffer.Length - 1)
|
||||
{
|
||||
builder.AppendLine();
|
||||
|
@ -187,8 +187,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
}
|
||||
else if ((i + 1) % 8 == 0)
|
||||
{
|
||||
builder.Append(" ");
|
||||
charBuilder.Append(" ");
|
||||
builder.Append(' ');
|
||||
charBuilder.Append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
}
|
||||
|
||||
builder.Append(new string(' ', padLength));
|
||||
builder.Append(charBuilder.ToString());
|
||||
builder.Append(charBuilder);
|
||||
}
|
||||
|
||||
_logger.LogDebug(builder.ToString());
|
||||
|
|
|
@ -350,7 +350,7 @@ namespace CodeGenerator
|
|||
|
||||
static string AppendSwitchSection(int length, IList<KnownHeader> values)
|
||||
{
|
||||
var useVarForFirstTerm = values.Count() > 1 && values.Select(h => h.FirstNameIgnoreCaseSegment()).Distinct().Count() == 1;
|
||||
var useVarForFirstTerm = values.Count > 1 && values.Select(h => h.FirstNameIgnoreCaseSegment()).Distinct().Count() == 1;
|
||||
var firstTermVarExpression = values.Select(h => h.FirstNameIgnoreCaseSegment()).FirstOrDefault();
|
||||
var firstTermVar = $"firstTerm{length}";
|
||||
|
||||
|
@ -1188,7 +1188,7 @@ $@" private void Clear(long bitsToClear)
|
|||
return;
|
||||
}}")}
|
||||
}}
|
||||
{(hi.Index + 1 < loop.Headers.Count() ? $"goto case {hi.Index + 1};" : "return;")}")}
|
||||
{(hi.Index + 1 < loop.Headers.Length ? $"goto case {hi.Index + 1};" : "return;")}")}
|
||||
default:
|
||||
return;
|
||||
}}
|
||||
|
@ -1272,7 +1272,7 @@ $@" private void Clear(long bitsToClear)
|
|||
{{{Each(loop.Headers.Where(header => header.Identifier != "ContentLength"), header => $@"
|
||||
case {header.Index}:
|
||||
goto Header{header.Identifier};")}
|
||||
{(!loop.ClassName.Contains("Trailers") ? $@"case {loop.Headers.Count() - 1}:
|
||||
{(!loop.ClassName.Contains("Trailers") ? $@"case {loop.Headers.Length - 1}:
|
||||
goto HeaderContentLength;" : "")}
|
||||
default:
|
||||
goto ExtraHeaders;
|
||||
|
@ -1286,12 +1286,12 @@ $@" private void Clear(long bitsToClear)
|
|||
")}_next = {header.Index + 1};
|
||||
return true;
|
||||
}}")}
|
||||
{(!loop.ClassName.Contains("Trailers") ? $@"HeaderContentLength: // case {loop.Headers.Count() - 1}
|
||||
{(!loop.ClassName.Contains("Trailers") ? $@"HeaderContentLength: // case {loop.Headers.Length - 1}
|
||||
if (_collection._contentLength.HasValue)
|
||||
{{
|
||||
_current = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_collection._contentLength.Value));
|
||||
{(loop.ClassName.Contains("Request") ? "" : @"_currentKnownType = KnownHeaderType.ContentLength;
|
||||
")}_next = {loop.Headers.Count()};
|
||||
")}_next = {loop.Headers.Length};
|
||||
return true;
|
||||
}}" : "")}
|
||||
ExtraHeaders:
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Http2Cat
|
|||
public static readonly byte[] _helloBytes = Encoding.ASCII.GetBytes("hello");
|
||||
public static readonly byte[] _worldBytes = Encoding.ASCII.GetBytes("world");
|
||||
public static readonly byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("hello, world");
|
||||
public static readonly byte[] _noData = new byte[0];
|
||||
public static readonly byte[] _noData = Array.Empty<byte>();
|
||||
public static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2PeerSettings.MinAllowedMaxFrameSize));
|
||||
|
||||
internal readonly Http2PeerSettings _clientSettings = new Http2PeerSettings();
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
|
|||
private const int NumberOfIPv6Labels = 8;
|
||||
// Lower case hex, no leading zeros
|
||||
private const string IPv6NumberFormat = "{0:x}";
|
||||
private const string IPv6StringSeparator = ":";
|
||||
private const char IPv6StringSeparator = ':';
|
||||
private const string IPv4StringFormat = "{0:d}.{1:d}.{2:d}.{3:d}";
|
||||
|
||||
internal const int IPv6AddressSize = 28;
|
||||
|
@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
|
|||
{
|
||||
if (i > WriteableOffset)
|
||||
{
|
||||
bytes.Append(",");
|
||||
bytes.Append(',');
|
||||
}
|
||||
bytes.Append(this[i].ToString(NumberFormatInfo.InvariantInfo));
|
||||
}
|
||||
|
|
|
@ -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.Collections.Generic;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
|
@ -8,7 +9,7 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
|
|||
{
|
||||
internal static class HeaderParser
|
||||
{
|
||||
internal static IEnumerable<string> Empty = new string[0];
|
||||
internal static IEnumerable<string> Empty = Array.Empty<string>();
|
||||
|
||||
// Split on commas, except in quotes
|
||||
internal static IEnumerable<string> SplitValues(StringValues values)
|
||||
|
|
|
@ -37,19 +37,19 @@ namespace Microsoft.Extensions.StackTrace.Sources
|
|||
{
|
||||
builder
|
||||
.Append(DeclaringTypeName)
|
||||
.Append(".");
|
||||
.Append('.');
|
||||
}
|
||||
|
||||
builder.Append(Name);
|
||||
builder.Append(GenericArguments);
|
||||
|
||||
builder.Append("(");
|
||||
builder.Append('(');
|
||||
builder.AppendJoin(", ", Parameters.Select(p => p.ToString()));
|
||||
builder.Append(")");
|
||||
builder.Append(')');
|
||||
|
||||
if (!string.IsNullOrEmpty(SubMethod))
|
||||
{
|
||||
builder.Append("+");
|
||||
builder.Append('+');
|
||||
builder.Append(SubMethod);
|
||||
builder.Append("()");
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ namespace Microsoft.Extensions.StackTrace.Sources
|
|||
{
|
||||
builder
|
||||
.Append(Prefix)
|
||||
.Append(" ");
|
||||
.Append(' ');
|
||||
}
|
||||
|
||||
builder.Append(Type);
|
||||
builder.Append(" ");
|
||||
builder.Append(' ');
|
||||
builder.Append(Name);
|
||||
|
||||
return builder.ToString();
|
||||
|
|
|
@ -4338,8 +4338,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
var messages = await messagePromise;
|
||||
|
||||
// add one because this includes the completion
|
||||
Assert.Equal(phrases.Count() + 1, messages.Count);
|
||||
for (var i = 0; i < phrases.Count(); i++)
|
||||
Assert.Equal(phrases.Length + 1, messages.Count);
|
||||
for (var i = 0; i < phrases.Length; i++)
|
||||
{
|
||||
Assert.Equal("echo:" + phrases[i], ((StreamItemMessage)messages[i]).Item);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace Microsoft.Extensions.Tools.Internal
|
|||
public TemporaryCSharpProject WithItem(ItemSpec item)
|
||||
{
|
||||
var sb = new StringBuilder("<");
|
||||
sb.Append(item.Name).Append(" ");
|
||||
sb.Append(item.Name).Append(' ');
|
||||
if (item.Include != null) sb.Append(" Include=\"").Append(item.Include).Append('"');
|
||||
if (item.Remove != null) sb.Append(" Remove=\"").Append(item.Remove).Append('"');
|
||||
if (item.Update != null) sb.Append(" Update=\"").Append(item.Update).Append('"');
|
||||
|
|
Загрузка…
Ссылка в новой задаче