当前位置: 首页>>代码示例>>C#>>正文


C# Syntax.NameSyntax类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax的典型用法代码示例。如果您正苦于以下问题:C# NameSyntax类的具体用法?C# NameSyntax怎么用?C# NameSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NameSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了NameSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryClassifySymbol

        private bool TryClassifySymbol(
            NameSyntax name,
            SymbolInfo symbolInfo,
            SemanticModel semanticModel,
            CancellationToken cancellationToken,
            out IEnumerable<ClassifiedSpan> result)
        {
            if (symbolInfo.CandidateReason == CandidateReason.Ambiguous)
            {
                return TryClassifyAmbiguousSymbol(name, symbolInfo, semanticModel, cancellationToken, out result);
            }

            // Only classify if we get one good symbol back, or if it bound to a constructor symbol with
            // overload resolution/accessibility errors, or bound to type/constructor and type wasn't creatable.
            var symbol = TryGetSymbol(name, symbolInfo, semanticModel);

            ClassifiedSpan classifiedSpan;
            if (TryClassifySymbol(name, symbol, semanticModel, cancellationToken, out classifiedSpan))
            {
                result = SpecializedCollections.SingletonEnumerable(classifiedSpan);
                return true;
            }

            result = null;
            return false;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:26,代码来源:NameSyntaxClassifier.cs

示例2: AppendName

            private static void AppendName(StringBuilder builder, NameSyntax name)
            {
                if (name.Kind() == SyntaxKind.QualifiedName)
                {
                    AppendName(builder, ((QualifiedNameSyntax)name).Left);
                }

                switch (name.Kind())
                {
                    case SyntaxKind.IdentifierName:
                        AppendDotIfNeeded(builder);
                        builder.Append(((IdentifierNameSyntax)name).Identifier.ValueText);
                        break;

                    case SyntaxKind.GenericName:
                        var genericName = (GenericNameSyntax)name;
                        AppendDotIfNeeded(builder);
                        builder.Append(genericName.Identifier.ValueText);
                        AppendArity(builder, genericName.Arity);
                        break;

                    case SyntaxKind.AliasQualifiedName:
                        var aliasQualifiedName = (AliasQualifiedNameSyntax)name;
                        AppendName(builder, aliasQualifiedName.Alias);
                        builder.Append("::");
                        AppendName(builder, aliasQualifiedName.Name);
                        break;

                    case SyntaxKind.QualifiedName:
                        AppendName(builder, ((QualifiedNameSyntax)name).Right);
                        break;
                }
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:33,代码来源:CSharpCodeModelService.NodeNameGenerator.cs

示例3: GetCompletionsOffOfExplicitInterfaceAsync

        private async Task<IEnumerable<CompletionItem>> GetCompletionsOffOfExplicitInterfaceAsync(
            Document document, SemanticModel semanticModel, int position, NameSyntax name, CancellationToken cancellationToken)
        {
            // Bind the interface name which is to the left of the dot
            var syntaxTree = semanticModel.SyntaxTree;
            var nameBinding = semanticModel.GetSymbolInfo(name, cancellationToken);
            var context = CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken);

            var symbol = nameBinding.Symbol as ITypeSymbol;
            if (symbol == null || symbol.TypeKind != TypeKind.Interface)
            {
                return SpecializedCollections.EmptyEnumerable<CompletionItem>();
            }

            var members = semanticModel.LookupSymbols(
                position: name.SpanStart,
                container: symbol)
                    .Where(s => !s.IsStatic)
                    .FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);

            // We're going to create a entry for each one, including the signature
            var completions = new List<CompletionItem>();

            var signatureDisplayFormat =
                new SymbolDisplayFormat(
                    genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
                    memberOptions:
                        SymbolDisplayMemberOptions.IncludeParameters,
                    parameterOptions:
                        SymbolDisplayParameterOptions.IncludeName |
                        SymbolDisplayParameterOptions.IncludeType |
                        SymbolDisplayParameterOptions.IncludeParamsRefOut,
                    miscellaneousOptions:
                        SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
                        SymbolDisplayMiscellaneousOptions.UseSpecialTypes);

            var namePosition = name.SpanStart;

            var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
            var textChangeSpan = CompletionUtilities.GetTextChangeSpan(text, context.Position);

            foreach (var member in members)
            {
                var displayString = member.ToMinimalDisplayString(semanticModel, namePosition, signatureDisplayFormat);
                var memberCopied = member;
                var insertionText = displayString;

                completions.Add(new SymbolCompletionItem(
                    this,
                    displayString,
                    insertionText: insertionText,
                    filterSpan: textChangeSpan,
                    position: position,
                    symbols: new List<ISymbol> { member },
                    context: context,
                    rules: ItemRules.Instance));
            }

            return completions;
        }
开发者ID:noahstein,项目名称:roslyn,代码行数:60,代码来源:ExplicitInterfaceCompletionProvider.cs

示例4: BuildName

        private static void BuildName(NameSyntax nameSyntax, StringBuilder builder, bool includeAlias)
        {
            if (nameSyntax.IsKind(SyntaxKind.IdentifierName))
            {
                var identifierNameSyntax = (IdentifierNameSyntax)nameSyntax;
                builder.Append(identifierNameSyntax.Identifier.ValueText);
            }
            else if (nameSyntax.IsKind(SyntaxKind.QualifiedName))
            {
                var qualifiedNameSyntax = (QualifiedNameSyntax)nameSyntax;
                BuildName(qualifiedNameSyntax.Left, builder, includeAlias);
                builder.Append(DotChar);
                BuildName(qualifiedNameSyntax.Right, builder, includeAlias);
            }
            else if (nameSyntax.IsKind(SyntaxKind.GenericName))
            {
                var genericNameSyntax = (GenericNameSyntax)nameSyntax;
                builder.AppendFormat("{0}{1}", genericNameSyntax.Identifier.ValueText, genericNameSyntax.TypeArgumentList.ToString());
            }
            else if (nameSyntax.IsKind(SyntaxKind.AliasQualifiedName))
            {
                var aliasQualifiedNameSyntax = (AliasQualifiedNameSyntax)nameSyntax;
                if (includeAlias)
                {
                    builder.Append(aliasQualifiedNameSyntax.Alias.Identifier.ValueText);
                    builder.Append("::");
                }

                builder.Append(aliasQualifiedNameSyntax.Name.Identifier.ValueText);
            }
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:31,代码来源:NameSyntaxHelpers.cs

示例5: IsNamespaceName

        private static bool IsNamespaceName(NameSyntax name)
        {
            while (name.Parent is NameSyntax)
            {
                name = (NameSyntax)name.Parent;
            }

            return name.IsParentKind(SyntaxKind.NamespaceDeclaration);
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:9,代码来源:NameSyntaxClassifier.cs

示例6: IntroduceQueryLocalForSingleOccurrence

        private Document IntroduceQueryLocalForSingleOccurrence(
            SemanticDocument document,
            ExpressionSyntax expression,
            NameSyntax newLocalName,
            LetClauseSyntax letClause,
            bool allOccurrences,
            CancellationToken cancellationToken)
        {
            var oldClause = expression.GetAncestors<SyntaxNode>().First(IsAnyQueryClause);
            var newClause = Rewrite(
                document, expression, newLocalName, document, oldClause, allOccurrences, cancellationToken);

            var oldQuery = (QueryBodySyntax)oldClause.Parent;
            var newQuery = GetNewQuery(oldQuery, oldClause, newClause, letClause);

            var newRoot = document.Root.ReplaceNode(oldQuery, newQuery);
            return document.Document.WithSyntaxRoot(newRoot);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:18,代码来源:CSharpIntroduceVariableService_IntroduceQueryLocal.cs

示例7: TryGetSymbol

        private static ISymbol TryGetSymbol(NameSyntax name, SymbolInfo symbolInfo, SemanticModel semanticModel)
        {
            if (symbolInfo.Symbol == null && symbolInfo.CandidateSymbols.Length > 0)
            {
                var firstSymbol = symbolInfo.CandidateSymbols[0];

                switch (symbolInfo.CandidateReason)
                {
                    case CandidateReason.NotAValue:
                        return firstSymbol;

                    case CandidateReason.NotCreatable:
                        // We want to color types even if they can't be constructed.
                        if (firstSymbol.IsConstructor() || firstSymbol is ITypeSymbol)
                        {
                            return firstSymbol;
                        }

                        break;

                    case CandidateReason.OverloadResolutionFailure:
                        // If we couldn't bind to a constructor, still classify the type.
                        if (firstSymbol.IsConstructor())
                        {
                            return firstSymbol;
                        }

                        break;

                    case CandidateReason.Inaccessible:
                        // If a constructor wasn't accessible, still classify the type if it's accessible.
                        if (firstSymbol.IsConstructor() && semanticModel.IsAccessible(name.SpanStart, firstSymbol.ContainingType))
                        {
                            return firstSymbol;
                        }

                        break;
                }
            }

            return symbolInfo.Symbol;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:42,代码来源:NameSyntaxClassifier.cs

示例8: ClassifyTypeSyntax

        private IEnumerable<ClassifiedSpan> ClassifyTypeSyntax(
            NameSyntax name,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            if (!IsNamespaceName(name))
            {
                var symbolInfo = semanticModel.GetSymbolInfo(name, cancellationToken);

                IEnumerable<ClassifiedSpan> result;
                if (TryClassifySymbol(name, symbolInfo, semanticModel, cancellationToken, out result) ||
                    TryClassifyFromIdentifier(name, symbolInfo, out result) ||
                    TryClassifyValueIdentifier(name, symbolInfo, out result))
                {
                    return result;
                }
            }

            return null;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:20,代码来源:NameSyntaxClassifier.cs

示例9: CheckNameSyntax

        private static void CheckNameSyntax(SyntaxNodeAnalysisContext context, NameSyntax nameSyntax)
        {
            if (nameSyntax == null || nameSyntax.IsMissing)
            {
                return;
            }

            QualifiedNameSyntax qualifiedNameSyntax = nameSyntax as QualifiedNameSyntax;
            if (qualifiedNameSyntax != null)
            {
                CheckNameSyntax(context, qualifiedNameSyntax.Left);
                CheckNameSyntax(context, qualifiedNameSyntax.Right);
                return;
            }

            SimpleNameSyntax simpleNameSyntax = nameSyntax as SimpleNameSyntax;
            if (simpleNameSyntax != null)
            {
                CheckElementNameToken(context, simpleNameSyntax.Identifier);
                return;
            }

            // TODO: any other cases?
        }
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:24,代码来源:SA1300ElementMustBeginWithUpperCaseLetter.cs

示例10: GetSymbolsOffOfName

        private static ImmutableArray<ISymbol> GetSymbolsOffOfName(
            CSharpSyntaxContext context,
            NameSyntax name,
            CancellationToken cancellationToken)
        {
            // Check if we're in an interesting situation like this:
            //
            //     int i = 5;
            //     i.          // <-- here
            //     List<string> ml = new List<string>();

            // The problem is that "i.List<string>" gets parsed as a type.  In this case we need to
            // try binding again as if "i" is an expression and not a type.  In order to do that, we
            // need to speculate as to what 'i' meant if it wasn't part of a local declaration's
            // type.

            if (name.IsFoundUnder<LocalDeclarationStatementSyntax>(d => d.Declaration.Type))
            {
                var speculativeBinding = context.SemanticModel.GetSpeculativeSymbolInfo(name.SpanStart, name, SpeculativeBindingOption.BindAsExpression);
                var container = context.SemanticModel.GetSpeculativeTypeInfo(name.SpanStart, name, SpeculativeBindingOption.BindAsExpression).Type;
                return GetSymbolsOffOfBoundExpression(context, name, name, speculativeBinding, container, cancellationToken);
            }

            // We're in a name-only context, since if we were an expression we'd be a
            // MemberAccessExpressionSyntax. Thus, let's do other namespaces and types.
            var nameBinding = context.SemanticModel.GetSymbolInfo(name, cancellationToken);

            var symbol = nameBinding.Symbol as INamespaceOrTypeSymbol;
            if (symbol != null)
            {
                if (context.IsNameOfContext)
                {
                    return context.SemanticModel.LookupSymbols(position: name.SpanStart, container: symbol);
                }

                var symbols = context.SemanticModel.LookupNamespacesAndTypes(
                    position: name.SpanStart,
                    container: symbol);

                if (context.IsNamespaceDeclarationNameContext)
                {
                    var declarationSyntax = name.GetAncestorOrThis<NamespaceDeclarationSyntax>();
                    return symbols.WhereAsArray(s => IsNonIntersectingNamespace(s, declarationSyntax));
                }

                // Filter the types when in a using directive, but not an alias.
                // 
                // Cases:
                //    using | -- Show namespaces
                //    using A.| -- Show namespaces
                //    using static | -- Show namespace and types
                //    using A = B.| -- Show namespace and types
                var usingDirective = name.GetAncestorOrThis<UsingDirectiveSyntax>();
                if (usingDirective != null && usingDirective.Alias == null)
                {
                    if (usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
                    {
                        return symbols.WhereAsArray(s => !s.IsDelegateType() && !s.IsInterfaceType());
                    }
                    else
                    {
                        symbols = symbols.WhereAsArray(s => s.IsNamespace());
                    }
                }

                if (symbols.Any())
                {
                    return symbols;
                }
            }

            return ImmutableArray<ISymbol>.Empty;
        }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:73,代码来源:CSharpRecommendationService.cs

示例11: GetDeclaredMember

        private Symbol GetDeclaredMember(NamespaceOrTypeSymbol container, TextSpan declarationSpan, NameSyntax name)
        {
            switch (name.Kind())
            {
                case SyntaxKind.GenericName:
                case SyntaxKind.IdentifierName:
                    return GetDeclaredMember(container, declarationSpan, ((SimpleNameSyntax)name).Identifier.ValueText);

                case SyntaxKind.QualifiedName:
                    var qn = (QualifiedNameSyntax)name;
                    var left = GetDeclaredMember(container, declarationSpan, qn.Left) as NamespaceOrTypeSymbol;
                    Debug.Assert((object)left != null);
                    return GetDeclaredMember(left, declarationSpan, qn.Right);

                case SyntaxKind.AliasQualifiedName:
                    // this is not supposed to happen, but we allow for errors don't we!
                    var an = (AliasQualifiedNameSyntax)name;
                    return GetDeclaredMember(container, declarationSpan, an.Name);

                default:
                    throw ExceptionUtilities.UnexpectedValue(name.Kind());
            }
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:23,代码来源:SyntaxTreeSemanticModel.cs

示例12: IsRewritableMethod

 bool IsRewritableMethod(NameSyntax methodNameSyntax)
 {
     var symbol = model.GetSymbolInfo(methodNameSyntax).Symbol as IMethodSymbol;
     return symbol != null && symbol.HasAttribute<MetaRewriteTypeArgsAttribute>(model.Compilation);
 }
开发者ID:VitalyTVA,项目名称:MetaSharp,代码行数:5,代码来源:Rewriter.cs

示例13: PreferPredefinedTypeKeywordInDeclarations

 private static bool PreferPredefinedTypeKeywordInDeclarations(NameSyntax name, OptionSet optionSet, SemanticModel semanticModel)
 {
     return !IsInMemberAccessContext(name) &&
            !InsideCrefReference(name) &&
            !InsideNameOfExpression(name, semanticModel) &&
            SimplificationHelpers.PreferPredefinedTypeKeywordInDeclarations(optionSet, semanticModel.Language);
 }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:7,代码来源:ExpressionSyntaxExtensions.cs

示例14: TryClassifyFromIdentifier

        private bool TryClassifyFromIdentifier(
            NameSyntax name,
            SymbolInfo symbolInfo,
            out IEnumerable<ClassifiedSpan> result)
        {
            // Okay - it wasn't a type. If the syntax matches "var q = from" or "q = from", and from
            // doesn't bind to anything then optimistically color from as a keyword.
            var identifierName = name as IdentifierNameSyntax;
            if (identifierName != null &&
                identifierName.Identifier.HasMatchingText(SyntaxKind.FromKeyword) &&
                symbolInfo.Symbol == null)
            {
                var token = identifierName.Identifier;
                if (identifierName.IsRightSideOfAnyAssignExpression() || identifierName.IsVariableDeclaratorValue())
                {
                    result = SpecializedCollections.SingletonEnumerable(
                        new ClassifiedSpan(token.Span, ClassificationTypeNames.Keyword));
                    return true;
                }
            }

            result = null;
            return false;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:24,代码来源:NameSyntaxClassifier.cs

示例15: PreferPredefinedTypeKeywordInDeclarations

 private static bool PreferPredefinedTypeKeywordInDeclarations(NameSyntax name, OptionSet optionSet, SemanticModel semanticModel)
 {
     return (name.Parent != null) && !(name.Parent is MemberAccessExpressionSyntax) &&
            !InsideCrefReference(name) && !InsideNameOfExpression(name, semanticModel) &&
            optionSet.GetOption(SimplificationOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, LanguageNames.CSharp);
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:6,代码来源:ExpressionSyntaxExtensions.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。