private void CheckPresenceOfTypeIdentifierAttribute()
        {
            // Have we already decoded well-known attributes?
            if (_lazyCustomAttributesBag?.IsDecodedWellKnownAttributeDataComputed == true)
            {
                return;
            }

            // We want this function to be as cheap as possible, it is called for every top level type
            // and we don't want to bind attributes attached to the declaration unless there is a chance
            // that one of them is TypeIdentifier attribute.
            ImmutableArray <SyntaxList <AttributeSyntax> > attributeLists = GetAttributeDeclarations();

            foreach (SyntaxList <AttributeSyntax> list in attributeLists)
            {
                var syntaxTree = list.Node.SyntaxTree;
                QuickAttributeChecker checker = this.DeclaringCompilation.GetBinderFactory(list.Node.SyntaxTree).GetBinder(list.Node).QuickAttributeChecker;

                foreach (AttributeSyntax attr in list)
                {
                    if (checker.IsPossibleMatch(attr, QuickAttributes.TypeIdentifier))
                    {
                        // This attribute syntax might be an application of TypeIdentifierAttribute.
                        // Let's bind it.
                        // For simplicity we bind all attributes.
                        GetAttributes();
                        return;
                    }
                }
            }
        }
Exemple #2
0
        internal QuickAttributeChecker AddAliasesIfAny(SyntaxList <ImportDirectiveSyntax> usingsSyntax)
        {
            if (usingsSyntax.Count == 0)
            {
                return(this);
            }

            QuickAttributeChecker newChecker = null;

            foreach (var usingDirective in usingsSyntax)
            {
                if (usingDirective.Alias != null)
                {
                    string name   = usingDirective.Alias.Name.Identifier.ValueText;
                    string target = usingDirective.Name.GetUnqualifiedName().Identifier.ValueText;

                    if (_nameToAttributeMap.TryGetValue(target, out var foundAttributes))
                    {
                        // copy the QuickAttributes from alias target to alias name
                        (newChecker ?? (newChecker = new QuickAttributeChecker(this))).AddName(name, foundAttributes);
                    }
                }
            }

            if (newChecker != null)
            {
#if DEBUG
                newChecker._sealed = true;
#endif
                return(newChecker);
            }

            return(this);
        }
Exemple #3
0
        private static QuickAttributeChecker CreatePredefinedQuickAttributeChecker()
        {
            var result = new QuickAttributeChecker();

            result.AddName(AttributeDescription.TypeIdentifierAttribute.Name, QuickAttributes.TypeIdentifier);
            result.AddName(AttributeDescription.TypeForwardedToAttribute.Name, QuickAttributes.TypeForwardedTo);

#if DEBUG
            result._sealed = true;
#endif
            return(result);
        }
Exemple #4
0
 private QuickAttributeChecker(QuickAttributeChecker previous)
 {
     _nameToAttributeMap = new Dictionary <string, QuickAttributes>(previous._nameToAttributeMap, StringComparer.Ordinal);
     // NOTE: caller must seal
 }