Пример #1
0
        internal static void LookupSymbolInUsings(
            ImmutableArray <NamespaceOrTypeAndUsingDirective> usings,
            LookupResult result,
            LookupConstraints constraints)
        {
            if (constraints.OriginalBinder.Flags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            bool callerIsSemanticModel = constraints.OriginalBinder.IsSemanticModelBinder;

            foreach (var typeOrNamespace in usings)
            {
                ImmutableArray <Symbol> candidates = Binder.GetCandidateMembers(constraints.WithQualifier(typeOrNamespace.NamespaceOrType));
                foreach (Symbol symbol in candidates)
                {
                    if (!IsValidLookupCandidateInUsings(symbol))
                    {
                        continue;
                    }

                    // Found a match in our list of normal using directives.  Mark the directive
                    // as being seen so that it won't be reported to the user as something that
                    // can be removed.
                    var res = constraints.OriginalBinder.CheckViability(symbol, constraints.WithAccessThroughType(null));
                    if (res.Kind == LookupResultKind.Viable)
                    {
                        MarkImportDirective(constraints.OriginalBinder.Compilation, typeOrNamespace.UsingDirective.SyntaxNode, callerIsSemanticModel);
                    }

                    result.MergeEqual(res);
                }
            }
        }
Пример #2
0
        // Note: we do not mark nodes when looking up arities or names.  This is because these two
        // types of lookup are only around to make the public
        // SemanticModel.LookupNames/LookupSymbols work and do not count as usages of the directives
        // when the actual code is bound.

        internal void AddLookupSymbolsInfo(LookupSymbolsInfo result, LookupConstraints constraints)
        {
            AddLookupSymbolsInfoInAliases(result, constraints);

            // Add types within namespaces imported through usings, but don't add nested namespaces.
            LookupOptions usingOptions = (constraints.Options & ~(LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) | LookupOptions.MustNotBeNamespace;

            AddLookupSymbolsInfoInUsings(this.Usings, result, constraints.WithOptions(usingOptions));
        }
Пример #3
0
        internal void LookupSymbol(LookupResult result, LookupConstraints constraints)
        {
            LookupSymbolInAliases(result, constraints);

            if (!result.IsMultiViable && (constraints.Options & LookupOptions.NamespaceAliasesOnly) == 0)
            {
                LookupSymbolInUsings(this.Usings, result, constraints);
            }
        }
Пример #4
0
        internal void AddLookupSymbolsInfoInAliases(LookupSymbolsInfo result, LookupConstraints constraints)
        {
            foreach (var(_, usingAlias) in this.UsingAliases)
            {
                AddAliasSymbolToResult(result, usingAlias.Alias, constraints);
            }

            foreach (var externAlias in this.ExternAliases)
            {
                AddAliasSymbolToResult(result, externAlias.Alias, constraints);
            }
        }
Пример #5
0
        internal void LookupSymbolInAliases(LookupResult result, LookupConstraints constraints)
        {
            bool callerIsSemanticModel = constraints.OriginalBinder.IsSemanticModelBinder;

            AliasAndUsingDirective alias;

            if (this.UsingAliases.TryGetValue(constraints.Name, out alias))
            {
                // Found a match in our list of normal aliases.  Mark the alias as being seen so that
                // it won't be reported to the user as something that can be removed.
                var res = constraints.OriginalBinder.CheckViability(alias.Alias, constraints.WithAccessThroughType(null));
                if (res.Kind == LookupResultKind.Viable)
                {
                    MarkImportDirective(alias.UsingDirective, callerIsSemanticModel);
                }

                result.MergeEqual(res);
            }

            foreach (var a in this.ExternAliases)
            {
                if (a.Alias.Name == constraints.Name)
                {
                    // Found a match in our list of extern aliases.  Mark the extern alias as being
                    // seen so that it won't be reported to the user as something that can be
                    // removed.
                    var res = constraints.OriginalBinder.CheckViability(a.Alias, constraints.WithAccessThroughType(null));
                    if (res.Kind == LookupResultKind.Viable)
                    {
                        MarkImportDirective(a.ExternAliasDirective, callerIsSemanticModel);
                    }

                    result.MergeEqual(res);
                }
            }
        }
Пример #6
0
        private static void AddLookupSymbolsInfoInUsings(
            ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, LookupSymbolsInfo result, LookupConstraints constraints)
        {
            if (constraints.OriginalBinder.Flags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            Debug.Assert(!constraints.Options.CanConsiderNamespaces());

            // look in all using namespaces
            foreach (var namespaceSymbol in usings)
            {
                foreach (var member in namespaceSymbol.NamespaceOrType.GetMembersUnordered())
                {
                    if (IsValidLookupCandidateInUsings(member) && constraints.OriginalBinder.CanAddLookupSymbolInfo(member, result, constraints, null))
                    {
                        result.AddSymbol(member, member.Name, member.MetadataName);
                    }
                }
            }
        }
Пример #7
0
        private static void AddAliasSymbolToResult(LookupSymbolsInfo result, AliasSymbol aliasSymbol, LookupConstraints constraints)
        {
            var targetSymbol = aliasSymbol.GetAliasTarget(basesBeingResolved: null);

            if (constraints.OriginalBinder.CanAddLookupSymbolInfo(targetSymbol, result, constraints.WithAccessThroughType(null), aliasSymbol: aliasSymbol))
            {
                result.AddSymbol(aliasSymbol, aliasSymbol.Name, aliasSymbol.Name);
            }
        }