Exemple #1
0
        private static ImmutableArray <AliasAndExternAliasDirective> BuildExternAliases(
            SyntaxList <ExternAliasDirectiveSyntax> syntaxList,
            InContainerBinder binder,
            DiagnosticBag diagnostics
            )
        {
            CSharpCompilation compilation = binder.Compilation;

            var builder = ArrayBuilder <AliasAndExternAliasDirective> .GetInstance();

            foreach (ExternAliasDirectiveSyntax aliasSyntax in syntaxList)
            {
                compilation.RecordImport(aliasSyntax);

                // Extern aliases not allowed in interactive submissions:
                if (compilation.IsSubmission)
                {
                    diagnostics.Add(ErrorCode.ERR_ExternAliasNotAllowed, aliasSyntax.Location);
                    continue;
                }

                // some n^2 action, but n should be very small.
                foreach (var existingAlias in builder)
                {
                    if (existingAlias.Alias.Name == aliasSyntax.Identifier.ValueText)
                    {
                        diagnostics.Add(
                            ErrorCode.ERR_DuplicateAlias,
                            existingAlias.Alias.Locations[0],
                            existingAlias.Alias.Name
                            );
                        break;
                    }
                }

                if (aliasSyntax.Identifier.ContextualKind() == SyntaxKind.GlobalKeyword)
                {
                    diagnostics.Add(
                        ErrorCode.ERR_GlobalExternAlias,
                        aliasSyntax.Identifier.GetLocation()
                        );
                }

                builder.Add(
                    new AliasAndExternAliasDirective(
                        new AliasSymbol(binder, aliasSyntax),
                        aliasSyntax
                        )
                    );
            }

            return(builder.ToImmutableAndFree());
        }