diff --git a/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs b/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs index 6c99ed0785ceb..3bb51945b48f3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs @@ -6,16 +6,14 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.Linq; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; -using System.Reflection; using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; -using Microsoft.CodeAnalysis; -using System.Diagnostics.CodeAnalysis; namespace Microsoft.CodeAnalysis.CSharp.Symbols { @@ -90,7 +88,7 @@ internal static bool IsTargetEarlyAttribute(NamedTypeSymbol attributeType, Attri Debug.Assert(!attributeType.IsErrorType()); int argumentCount = (attributeSyntax.ArgumentList != null) ? - attributeSyntax.ArgumentList.Arguments.Count((arg) => arg.NameEquals == null) : + attributeSyntax.ArgumentList.Arguments.Count(static (arg) => arg.NameEquals == null) : 0; return AttributeData.IsTargetEarlyAttribute(attributeType, argumentCount, description); } @@ -138,7 +136,7 @@ internal bool IsSecurityAttribute(CSharpCompilation compilation) { string className = this.AttributeClass.ToDisplayString(SymbolDisplayFormat.TestFormat); - if (!this.CommonConstructorArguments.Any() & !this.CommonNamedArguments.Any()) + if (this.CommonConstructorArguments.IsEmpty && this.CommonNamedArguments.IsEmpty) { return className; } @@ -343,7 +341,7 @@ private DeclarativeSecurityAction DecodeSecurityAttributeAction(Symbol targetSym Debug.Assert(this.IsSecurityAttribute(compilation)); var ctorArgs = this.CommonConstructorArguments; - if (!ctorArgs.Any()) + if (ctorArgs.IsEmpty) { // NOTE: Security custom attributes must have a valid SecurityAction as its first argument, we have none here. // NOTE: Ideally, we should always generate 'CS7048: First argument to a security attribute must be a valid SecurityAction' for this case. @@ -365,7 +363,7 @@ private DeclarativeSecurityAction DecodeSecurityAttributeAction(Symbol targetSym } else { - TypedConstant firstArg = ctorArgs.First(); + TypedConstant firstArg = ctorArgs[0]; var firstArgType = (TypeSymbol?)firstArg.TypeInternal; if (firstArgType is object && firstArgType.Equals(compilation.GetWellKnownType(WellKnownType.System_Security_Permissions_SecurityAction))) { diff --git a/src/Compilers/Core/Portable/Syntax/SeparatedSyntaxListExtensions.cs b/src/Compilers/Core/Portable/Syntax/SeparatedSyntaxListExtensions.cs new file mode 100644 index 0000000000000..695e8ffda391a --- /dev/null +++ b/src/Compilers/Core/Portable/Syntax/SeparatedSyntaxListExtensions.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Microsoft.CodeAnalysis +{ + internal static class SeparatedSyntaxListExtensions + { + internal static int Count(this SeparatedSyntaxList list, Func predicate) + where TNode : SyntaxNode + { + int n = list.Count; + int count = 0; + for (int i = 0; i < n; i++) + { + if (predicate(list[i])) + { + count++; + } + } + + return count; + } + } +}