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


C# this.CSharpKind方法代码示例

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


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

示例1: GetNameToken

 public static SyntaxToken GetNameToken(this NameSyntax nameSyntax)
 {
     while (true)
     {
         if (nameSyntax.CSharpKind() == SyntaxKind.IdentifierName)
         {
             return ((IdentifierNameSyntax)nameSyntax).Identifier;
         }
         else if (nameSyntax.CSharpKind() == SyntaxKind.QualifiedName)
         {
             nameSyntax = ((QualifiedNameSyntax)nameSyntax).Right;
         }
         else if (nameSyntax.CSharpKind() == SyntaxKind.GenericName)
         {
             return ((GenericNameSyntax)nameSyntax).Identifier;
         }
         else if (nameSyntax.CSharpKind() == SyntaxKind.AliasQualifiedName)
         {
             nameSyntax = ((AliasQualifiedNameSyntax)nameSyntax).Name;
         }
         else
         {
             throw new NotSupportedException();
         }
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:26,代码来源:NameSyntaxExtensions.cs

示例2: IsLiteral

 public static bool IsLiteral(this SyntaxToken token)
 {
     return token.CSharpKind() == SyntaxKind.CharacterLiteralToken
         || token.CSharpKind() == SyntaxKind.FalseKeyword
         || token.CSharpKind() == SyntaxKind.NumericLiteralToken
         || token.CSharpKind() == SyntaxKind.StringLiteralToken
         || token.CSharpKind() == SyntaxKind.TrueKeyword;
 }
开发者ID:riversky,项目名称:roslyn,代码行数:8,代码来源:SyntaxTokenExtensions.cs

示例3: GetCommentText

        public static string GetCommentText(this SyntaxTrivia trivia)
        {
            var commentText = trivia.ToString();
            if (trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia)
            {
                if (commentText.StartsWith("//"))
                {
                    commentText = commentText.Substring(2);
                }

                return commentText.TrimStart();
            }
            else if (trivia.CSharpKind() == SyntaxKind.MultiLineCommentTrivia)
            {
                var textBuilder = new StringBuilder();

                if (commentText.EndsWith("*/"))
                {
                    commentText = commentText.Substring(0, commentText.Length - 2);
                }

                if (commentText.StartsWith("/*"))
                {
                    commentText = commentText.Substring(2);
                }

                commentText = commentText.Trim();

                var newLine = Environment.NewLine;
                var lines = commentText.Split(new[] { newLine }, StringSplitOptions.None);
                foreach (var line in lines)
                {
                    var trimmedLine = line.Trim();

                    // Note: we trim leading '*' characters in multi-line comments.
                    // If the '*' was intentional, sorry, it's gone.
                    if (trimmedLine.StartsWith("*"))
                    {
                        trimmedLine = trimmedLine.TrimStart('*');
                        trimmedLine = trimmedLine.TrimStart();
                    }

                    textBuilder.AppendLine(trimmedLine);
                }

                // remove last line break
                textBuilder.Remove(textBuilder.Length - newLine.Length, newLine.Length);

                return textBuilder.ToString();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:55,代码来源:SyntaxTriviaExtensions.cs

示例4: GetNameToken

        public static SyntaxToken GetNameToken(this MemberDeclarationSyntax member)
        {
            if (member != null)
            {
                switch (member.CSharpKind())
                {
                    case SyntaxKind.EnumDeclaration:
                        return ((EnumDeclarationSyntax)member).Identifier;
                    case SyntaxKind.ClassDeclaration:
                    case SyntaxKind.InterfaceDeclaration:
                    case SyntaxKind.StructDeclaration:
                        return ((TypeDeclarationSyntax)member).Identifier;
                    case SyntaxKind.DelegateDeclaration:
                        return ((DelegateDeclarationSyntax)member).Identifier;
                    case SyntaxKind.FieldDeclaration:
                        return ((FieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
                    case SyntaxKind.EventFieldDeclaration:
                        return ((EventFieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
                    case SyntaxKind.PropertyDeclaration:
                        return ((PropertyDeclarationSyntax)member).Identifier;
                    case SyntaxKind.EventDeclaration:
                        return ((EventDeclarationSyntax)member).Identifier;
                    case SyntaxKind.MethodDeclaration:
                        return ((MethodDeclarationSyntax)member).Identifier;
                }
            }

            // Constructors, destructors, indexers and operators don't have names.
            return default(SyntaxToken);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:30,代码来源:MemberDeclarationSyntaxExtensions.cs

示例5: MatchesKind

        public static bool MatchesKind(this SyntaxNode node, params SyntaxKind[] kinds)
        {
            if (node == null)
            {
                return false;
            }

            return kinds.Contains(node.CSharpKind());
        }
开发者ID:riversky,项目名称:roslyn,代码行数:9,代码来源:CommonSyntaxNodeExtensions.cs

示例6: IsCompleteMultiLineComment

        public static bool IsCompleteMultiLineComment(this SyntaxTrivia trivia)
        {
            if (trivia.CSharpKind() != SyntaxKind.MultiLineCommentTrivia)
            {
                return false;
            }

            var text = trivia.ToFullString();
            return text.Length >= 4
                && text[text.Length - 1] == '/'
                && text[text.Length - 2] == '*';
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:12,代码来源:SyntaxTriviaExtensions.cs

示例7: WithParameters

        public static BaseParameterListSyntax WithParameters(
            this BaseParameterListSyntax parameterList,
            SeparatedSyntaxList<ParameterSyntax> parameters)
        {
            switch (parameterList.CSharpKind())
            {
                case SyntaxKind.BracketedParameterList:
                    return ((BracketedParameterListSyntax)parameterList).WithParameters(parameters);
                case SyntaxKind.ParameterList:
                    return ((ParameterListSyntax)parameterList).WithParameters(parameters);
            }

            throw Contract.Unreachable;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:14,代码来源:BaseParameterListSyntaxExtensions.cs

示例8: GetCloseToken

        public static SyntaxToken GetCloseToken(this BaseArgumentListSyntax node)
        {
            if (node != null)
            {
                switch (node.CSharpKind())
                {
                    case SyntaxKind.ArgumentList:
                        return ((ArgumentListSyntax)node).CloseParenToken;
                    case SyntaxKind.BracketedArgumentList:
                        return ((BracketedArgumentListSyntax)node).CloseBracketToken;
                }
            }

            return default(SyntaxToken);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:15,代码来源:BaseArgumentListSyntaxExtensions.cs

示例9: GetKind

        public static string GetKind(this SyntaxNode node)
        {
            var kind = string.Empty;

            if (node.Language == LanguageNames.CSharp)
            {
                kind = node.CSharpKind().ToString();
            }
            else 
            {
                kind = node.VisualBasicKind().ToString();
            }

            return kind;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:15,代码来源:SyntaxKindHelper.cs

示例10: AddMembers

        public static TypeDeclarationSyntax AddMembers(
            this TypeDeclarationSyntax node, params MemberDeclarationSyntax[] members)
        {
            switch (node.CSharpKind())
            {
                case SyntaxKind.ClassDeclaration:
                    return ((ClassDeclarationSyntax)node).AddMembers(members);
                case SyntaxKind.InterfaceDeclaration:
                    return ((InterfaceDeclarationSyntax)node).AddMembers(members);
                case SyntaxKind.StructDeclaration:
                    return ((StructDeclarationSyntax)node).AddMembers(members);
            }

            throw Contract.Unreachable;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:TypeDeclarationSyntaxExtensions.cs

示例11: WithModifiers

        public static TypeDeclarationSyntax WithModifiers(
            this TypeDeclarationSyntax node, SyntaxTokenList modifiers)
        {
            switch (node.CSharpKind())
            {
                case SyntaxKind.ClassDeclaration:
                    return ((ClassDeclarationSyntax)node).WithModifiers(modifiers);
                case SyntaxKind.InterfaceDeclaration:
                    return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers);
                case SyntaxKind.StructDeclaration:
                    return ((StructDeclarationSyntax)node).WithModifiers(modifiers);
            }

            throw Contract.Unreachable;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:TypeDeclarationSyntaxExtensions.cs

示例12: WithAttributeLists

        public static TypeDeclarationSyntax WithAttributeLists(
            this TypeDeclarationSyntax node, SyntaxList<AttributeListSyntax> attributes)
        {
            switch (node.CSharpKind())
            {
                case SyntaxKind.ClassDeclaration:
                    return ((ClassDeclarationSyntax)node).WithAttributeLists(attributes);
                case SyntaxKind.InterfaceDeclaration:
                    return ((InterfaceDeclarationSyntax)node).WithAttributeLists(attributes);
                case SyntaxKind.StructDeclaration:
                    return ((StructDeclarationSyntax)node).WithAttributeLists(attributes);
            }

            throw Contract.Unreachable;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:TypeDeclarationSyntaxExtensions.cs

示例13: GetAttributes

        public static SyntaxList<AttributeListSyntax> GetAttributes(this MemberDeclarationSyntax member)
        {
            if (member != null)
            {
                switch (member.CSharpKind())
                {
                    case SyntaxKind.EnumDeclaration:
                        return ((EnumDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.EnumMemberDeclaration:
                        return ((EnumMemberDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.ClassDeclaration:
                    case SyntaxKind.InterfaceDeclaration:
                    case SyntaxKind.StructDeclaration:
                        return ((TypeDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.DelegateDeclaration:
                        return ((DelegateDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.FieldDeclaration:
                        return ((FieldDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.EventFieldDeclaration:
                        return ((EventFieldDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.ConstructorDeclaration:
                        return ((ConstructorDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.DestructorDeclaration:
                        return ((DestructorDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.PropertyDeclaration:
                        return ((PropertyDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.EventDeclaration:
                        return ((EventDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.IndexerDeclaration:
                        return ((IndexerDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.OperatorDeclaration:
                        return ((OperatorDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.ConversionOperatorDeclaration:
                        return ((ConversionOperatorDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.MethodDeclaration:
                        return ((MethodDeclarationSyntax)member).AttributeLists;
                    case SyntaxKind.IncompleteMember:
                        return ((IncompleteMemberSyntax)member).AttributeLists;
                }
            }

            return SyntaxFactory.List<AttributeListSyntax>();
        }
开发者ID:riversky,项目名称:roslyn,代码行数:43,代码来源:MemberDeclarationSyntaxExtensions.cs

示例14: IsCompoundAssignExpression

        public static bool IsCompoundAssignExpression(this BinaryExpressionSyntax binaryExpression)
        {
            if (binaryExpression != null)
            {
                switch (binaryExpression.CSharpKind())
                {
                    case SyntaxKind.AddAssignmentExpression:
                    case SyntaxKind.SubtractAssignmentExpression:
                    case SyntaxKind.MultiplyAssignmentExpression:
                    case SyntaxKind.DivideAssignmentExpression:
                    case SyntaxKind.ModuloAssignmentExpression:
                    case SyntaxKind.AndAssignmentExpression:
                    case SyntaxKind.ExclusiveOrAssignmentExpression:
                    case SyntaxKind.OrAssignmentExpression:
                    case SyntaxKind.LeftShiftAssignmentExpression:
                    case SyntaxKind.RightShiftAssignmentExpression:
                        return true;
                }
            }

            return false;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:22,代码来源:BinaryExpressionSyntaxExtensions.cs

示例15: IsCloseParenInArgumentList

 public static bool IsCloseParenInArgumentList(this SyntaxToken token)
 {
     return token.CSharpKind() == SyntaxKind.CloseParenToken && token.Parent.CSharpKind() == SyntaxKind.ArgumentList;
 }
开发者ID:nagyist,项目名称:roslyn,代码行数:4,代码来源:FormattingHelpers.cs


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