Example #1
0
        /// <summary>
        /// Checks if an applied attribute with the given attributeType matches the namespace name and type name of the given early attribute's description
        /// and the attribute description has a signature with parameter count equal to the given attributeArgCount.
        /// NOTE: We don't allow early decoded attributes to have optional parameters.
        /// </summary>
        internal static bool IsTargetEarlyAttribute(
            INamedTypeSymbolInternal attributeType,
            int attributeArgCount,
            AttributeDescription description
            )
        {
            if (attributeType.ContainingSymbol?.Kind != SymbolKind.Namespace)
            {
                return(false);
            }

            int attributeCtorsCount = description.Signatures.Length;

            for (int i = 0; i < attributeCtorsCount; i++)
            {
                int parameterCount = description.GetParameterCount(signatureIndex: i);

                // NOTE: Below assumption disallows early decoding well-known attributes with optional parameters.
                if (attributeArgCount == parameterCount)
                {
                    StringComparison options = description.MatchIgnoringCase
                        ? StringComparison.OrdinalIgnoreCase
                        : StringComparison.Ordinal;
                    return(attributeType.Name.Equals(description.Name, options) &&
                           namespaceMatch(
                               attributeType.ContainingNamespace,
                               description.Namespace,
                               options
                               ));
                }
            }

            return(false);
Example #2
0
        // compares by namespace and type name, ignores signatures
        private static bool EarlyDecodeIsTargetAttribute(NamedTypeSymbol attributeType, AttributeSyntax attributeSyntax, AttributeDescription description, bool skipParamCheck = false)
        {
            if (!skipParamCheck)
            {
                int parameterCount = description.GetParameterCount(signatureIndex: 0);
                int argumentCount = (attributeSyntax.ArgumentList != null) ? attributeSyntax.ArgumentList.Arguments.Count : 0;

                if (argumentCount != parameterCount)
                {
                    return false;
                }
            }

            Debug.Assert(!attributeType.IsErrorType());
            string actualNamespaceName = attributeType.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat);
            return actualNamespaceName.Equals(description.Namespace) && attributeType.Name.Equals(description.Name);
        }
Example #3
0
        // compares by namespace and type name, ignores signatures
        private static bool EarlyDecodeIsTargetAttribute(NamedTypeSymbol attributeType, AttributeSyntax attributeSyntax, AttributeDescription description, bool skipParamCheck = false)
        {
            if (!skipParamCheck)
            {
                int parameterCount = description.GetParameterCount(signatureIndex: 0);
                int argumentCount  = (attributeSyntax.ArgumentList != null) ? attributeSyntax.ArgumentList.Arguments.Count : 0;

                if (argumentCount != parameterCount)
                {
                    return(false);
                }
            }

            Debug.Assert(!attributeType.IsErrorType());
            string actualNamespaceName = attributeType.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat);

            return(actualNamespaceName.Equals(description.Namespace) && attributeType.Name.Equals(description.Name));
        }
Example #4
0
        /// <summary>
        /// Checks if an applied attribute with the given attributeType matches the namespace name and type name of the given early attribute's description
        /// and the attribute description has a signature with parameter count equal to the given attributeArgCount.
        /// NOTE: We don't allow early decoded attributes to have optional parameters.
        /// </summary>
        internal static bool IsTargetEarlyAttribute(INamedTypeSymbol attributeType, int attributeArgCount, AttributeDescription description)
        {
            int attributeCtorsCount = description.Signatures.Length;

            for (int i = 0; i < attributeCtorsCount; i++)
            {
                int parameterCount = description.GetParameterCount(signatureIndex: i);

                // NOTE: Below assumption disallows early decoding well-known attributes with optional parameters.
                if (attributeArgCount == parameterCount)
                {
                    string           actualNamespaceName = attributeType.ContainingNamespace.ToDisplayString(SymbolDisplayFormat.QualifiedNameOnlyFormat);
                    StringComparison options             = description.MatchIgnoringCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
                    return(actualNamespaceName.Equals(description.Namespace, options) && attributeType.Name.Equals(description.Name, options));
                }
            }

            return(false);
        }