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


C# SyntaxToken.IsVerbatimIdentifier方法代码示例

本文整理汇总了C#中SyntaxToken.IsVerbatimIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxToken.IsVerbatimIdentifier方法的具体用法?C# SyntaxToken.IsVerbatimIdentifier怎么用?C# SyntaxToken.IsVerbatimIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxToken的用法示例。


在下文中一共展示了SyntaxToken.IsVerbatimIdentifier方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNewIdentifierTokenFromToken

        private SyntaxToken CreateNewIdentifierTokenFromToken(SyntaxToken originalToken, bool escape)
        {
            var isVerbatimIdentifier = originalToken.IsVerbatimIdentifier();
            if (isVerbatimIdentifier == escape)
            {
                return originalToken;
            }

            var unescapedText = isVerbatimIdentifier ? originalToken.ToString().Substring(1) : originalToken.ToString();

            return escape
                ? originalToken.CopyAnnotationsTo(SyntaxFactory.VerbatimIdentifier(originalToken.LeadingTrivia, unescapedText, originalToken.ValueText, originalToken.TrailingTrivia))
                : originalToken.CopyAnnotationsTo(SyntaxFactory.Identifier(originalToken.LeadingTrivia, SyntaxKind.IdentifierToken, unescapedText, originalToken.ValueText, originalToken.TrailingTrivia));
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:14,代码来源:CSharpEscapingReducer.cs

示例2: RenameToken

            private SyntaxToken RenameToken(SyntaxToken oldToken, SyntaxToken newToken, string prefix, string suffix)
            {
                var parent = oldToken.Parent;
                string currentNewIdentifier = _isVerbatim ? _replacementText.Substring(1) : _replacementText;
                var oldIdentifier = newToken.ValueText;
                var isAttributeName = SyntaxFacts.IsAttributeName(parent);

                if (isAttributeName)
                {
                    Debug.Assert(_renamedSymbol.IsAttribute() || _aliasSymbol.Target.IsAttribute());
                    if (oldIdentifier != _renamedSymbol.Name)
                    {
                        string withoutSuffix;
                        if (currentNewIdentifier.TryGetWithoutAttributeSuffix(out withoutSuffix))
                        {
                            currentNewIdentifier = withoutSuffix;
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(prefix))
                    {
                        currentNewIdentifier = prefix + currentNewIdentifier;
                    }

                    if (!string.IsNullOrEmpty(suffix))
                    {
                        currentNewIdentifier = currentNewIdentifier + suffix;
                    }
                }

                // determine the canonical identifier name (unescaped, no unicode escaping, ...)
                string valueText = currentNewIdentifier;
                var kind = SyntaxFacts.GetKeywordKind(currentNewIdentifier);
                if (kind != SyntaxKind.None)
                {
                    valueText = SyntaxFacts.GetText(kind);
                }
                else
                {
                    var parsedIdentifier = SyntaxFactory.ParseName(currentNewIdentifier);
                    if (parsedIdentifier.IsKind(SyntaxKind.IdentifierName))
                    {
                        valueText = ((IdentifierNameSyntax)parsedIdentifier).Identifier.ValueText;
                    }
                }

                // TODO: we can't use escaped unicode characters in xml doc comments, so we need to pass the valuetext as text as well.
                // <param name="\u... is invalid.

                // if it's an attribute name we don't mess with the escaping because it might change overload resolution
                newToken = _isVerbatim || (isAttributeName && oldToken.IsVerbatimIdentifier())
                    ? newToken = newToken.CopyAnnotationsTo(SyntaxFactory.VerbatimIdentifier(newToken.LeadingTrivia, currentNewIdentifier, valueText, newToken.TrailingTrivia))
                    : newToken = newToken.CopyAnnotationsTo(SyntaxFactory.Identifier(newToken.LeadingTrivia, SyntaxKind.IdentifierToken, currentNewIdentifier, valueText, newToken.TrailingTrivia));

                if (_replacementTextValid)
                {
                    if (newToken.IsVerbatimIdentifier())
                    {
                        // a reference location should always be tried to be unescaped, whether it was escaped before rename 
                        // or the replacement itself is escaped.
                        newToken = newToken.WithAdditionalAnnotations(Simplifier.Annotation);
                    }
                    else
                    {
                        var semanticModel = GetSemanticModelForNode(parent, _speculativeModel ?? _semanticModel);
                        newToken = Simplification.CSharpSimplificationService.TryEscapeIdentifierToken(newToken, parent, semanticModel);
                    }
                }

                return newToken;
            }
开发者ID:nemec,项目名称:roslyn,代码行数:73,代码来源:CSharpRenameRewriterLanguageService.cs

示例3: IsVerbatimIdentifier

 public bool IsVerbatimIdentifier(SyntaxToken token)
 {
     return token.IsVerbatimIdentifier();
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:4,代码来源:CSharpSyntaxFactsService.cs


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