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


C# SyntaxTokenList类代码示例

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


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

示例1: IsStaticMember

        /// <summary>
        /// Only valid for field/constructor/property/method
        /// </summary>
        /// <param name="syntax"></param>
        /// <returns></returns>
        public static bool IsStaticMember(this MemberDeclarationSyntax syntax)
        {
            SyntaxTokenList modifiers = new SyntaxTokenList();
            switch (syntax.Kind())
            {
                case SyntaxKind.FieldDeclaration:
                    var field = syntax as FieldDeclarationSyntax;
                    modifiers = field.Modifiers;
                    break;

                case SyntaxKind.PropertyDeclaration:
                    var property = syntax as PropertyDeclarationSyntax;
                    modifiers = property.Modifiers;
                    break;

                case SyntaxKind.MethodDeclaration:
                    var method = syntax as MethodDeclarationSyntax;
                    modifiers = method.Modifiers;
                    break;

                case SyntaxKind.ConstructorDeclaration:
                    var ctor = syntax as ConstructorDeclarationSyntax;
                    modifiers = ctor.Modifiers;
                    break;
            }
            foreach (var modifier in modifiers)
            {
                if (modifier.Kind() == SyntaxKind.StaticKeyword)
                    return true;
            }
            return false;
        }
开发者ID:rexzh,项目名称:SharpJs,代码行数:37,代码来源:SyntaxExtensions.cs

示例2: MethodDeclaration

 public static MethodDeclarationSyntax MethodDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     TypeSyntax returnType,
     ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
     SyntaxToken identifier,
     TypeParameterListSyntax typeParameterList,
     ParameterListSyntax parameterList,
     SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
     BlockSyntax body,
     SyntaxToken semicolonToken)
 {
     return SyntaxFactory.MethodDeclaration(
         attributeLists,
         modifiers,
         default(SyntaxToken),
         returnType,
         explicitInterfaceSpecifier,
         identifier,
         typeParameterList,
         parameterList,
         constraintClauses,
         body,
         default(ArrowExpressionClauseSyntax),
         semicolonToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:MethodDeclarationSyntax.cs

示例3: AdjustAccessibility

		static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool isStatic, ref bool result)
		{
			isStatic = modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword);
			if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) &&
				modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) {
				acc = Accessibility.ProtectedOrInternal;
				result = true;
				return;
			}

			foreach (var mod in modifiers) {
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) {
					acc = Accessibility.Public;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) {
					acc = Accessibility.Private;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) {
					acc = Accessibility.Protected;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) {
					acc = Accessibility.Internal;
					result = true;
					return;
				}
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:33,代码来源:AstStockIcons.cs

示例4: CreateSpan

        private static TextSpan CreateSpan(SyntaxTokenList startOpt, SyntaxNodeOrToken startFallbackOpt, SyntaxNodeOrToken endOpt)
        {
            Debug.Assert(startFallbackOpt != default(SyntaxNodeOrToken) || endOpt != default(SyntaxNodeOrToken));

            int startPos;
            if (startOpt.Count > 0)
            {
                startPos = startOpt.First().SpanStart;
            }
            else if (startFallbackOpt != default(SyntaxNodeOrToken))
            {
                startPos = startFallbackOpt.SpanStart;
            }
            else
            {
                startPos = endOpt.SpanStart;
            }

            int endPos;
            if (endOpt != default(SyntaxNodeOrToken))
            {
                endPos = GetEndPosition(endOpt);
            }
            else
            {
                endPos = GetEndPosition(startFallbackOpt);
            }

            return TextSpan.FromBounds(startPos, endPos);
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:30,代码来源:LocalRewriter_SequencePoints.cs

示例5: HandleDefaultModifier

 static void HandleDefaultModifier(SyntaxNodeAnalysisContext context, SyntaxTokenList modifiers, SyntaxKind defaultModifier)
 {
     var index = modifiers.IndexOf(defaultModifier);
     if (index != -1)
     {
         context.ReportDiagnostic(Diagnostic.Create(Rule, modifiers[index].GetLocation()));
     }
 }
开发者ID:cincuranet,项目名称:ExplicitDefaultAccessModifiersAnalyzer,代码行数:8,代码来源:DiagnosticAnalyzer.cs

示例6: ChangeTypeAccessibilityInDocumentAsync

        private static async Task<Document> ChangeTypeAccessibilityInDocumentAsync(Solution solution, SyntaxTokenList newAccessibilityModifiers, Location typeLocation, CancellationToken cancellationToken)
        {
            var document = solution.GetDocument(typeLocation.SourceTree);
            var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var newRoot = ChangeTypeAccessibilityInSyntaxRoot(syntaxRoot, newAccessibilityModifiers, typeLocation, cancellationToken);

            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:9,代码来源:InconsistentAccessibilityCodeFixProvider.cs

示例7: TextAttribute

 public static XmlTextAttributeSyntax TextAttribute(XmlNameSyntax name, SyntaxKind quoteKind, SyntaxTokenList textTokens)
 {
     return SyntaxFactory.XmlTextAttribute(
         name,
         SyntaxFactory.Token(quoteKind),
         textTokens,
         SyntaxFactory.Token(quoteKind))
         .WithLeadingTrivia(SyntaxFactory.Whitespace(" "));
 }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:9,代码来源:XmlSyntaxFactory.cs

示例8: MarkUnsafe

 void MarkUnsafe(SyntaxTokenList modifiers, bool isUnsafe)
 {
     var state = unsafeStateStack.Pop();
     if (isUnsafe && !state.UseUnsafeConstructs)
     {
         ctx.ReportDiagnostic(Diagnostic.Create(
             descriptor,
             modifiers.First(m => m.IsKind(SyntaxKind.UnsafeKeyword)).GetLocation()
         ));
     }
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:11,代码来源:RedundantUnsafeContextAnalyzer.cs

示例9: DelegateDeclaration

 public static DelegateDeclarationSyntax DelegateDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken delegateKeyword, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken semicolonToken)
 {
     return DelegateDeclaration(
         attributeLists,
         modifiers, 
         delegateKeyword, 
         refKeyword: default(SyntaxToken), 
         returnType: returnType, 
         identifier: identifier, 
         typeParameterList: typeParameterList, 
         parameterList: parameterList, 
         constraintClauses: constraintClauses, 
         semicolonToken: semicolonToken);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:14,代码来源:DelegateDeclarationSyntax.cs

示例10: TypeDeclaration

 public static TypeDeclarationSyntax TypeDeclaration(SyntaxKind kind, SyntaxList<AttributeListSyntax> attributes, SyntaxTokenList modifiers, SyntaxToken keyword, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, BaseListSyntax baseList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken openBraceToken, SyntaxList<MemberDeclarationSyntax> members, SyntaxToken closeBraceToken, SyntaxToken semicolonToken)
 {
     switch (kind)
     {
         case SyntaxKind.ClassDeclaration:
             return SyntaxFactory.ClassDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
         case SyntaxKind.StructDeclaration:
             return SyntaxFactory.StructDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
         case SyntaxKind.InterfaceDeclaration:
             return SyntaxFactory.InterfaceDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
         default:
             throw new ArgumentException("kind");
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:TypeDeclarationSyntax.cs

示例11: ReplaceModifiers

        // This code was copied from the Roslyn code base (and slightly modified). It can be removed if
        // TypeDeclarationSyntaxExtensions.WithModifiers is made public (Roslyn issue #2186)
        private static TypeDeclarationSyntax ReplaceModifiers(TypeDeclarationSyntax node, SyntaxTokenList modifiers)
        {
            switch (node.Kind())
            {
            case SyntaxKind.ClassDeclaration:
                return ((ClassDeclarationSyntax)node).WithModifiers(modifiers);
            case SyntaxKind.InterfaceDeclaration:
                return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers);
            case SyntaxKind.StructDeclaration:
                return ((StructDeclarationSyntax)node).WithModifiers(modifiers);
            }

            return node;
        }
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:16,代码来源:SA1205CodeFixProvider.cs

示例12: PropertyDeclaration

 public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken)
 {
     return PropertyDeclaration(
         attributeLists,
         modifiers,
         refKeyword: default(SyntaxToken),
         type: type,
         explicitInterfaceSpecifier: explicitInterfaceSpecifier, 
         identifier: identifier, 
         accessorList: accessorList, 
         expressionBody: expressionBody, 
         initializer: initializer, 
         semicolonToken: semicolonToken);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:14,代码来源:PropertyDeclarationSyntax.cs

示例13: 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

示例14: DestructorDeclaration

 public static DestructorDeclarationSyntax DestructorDeclaration(
     SyntaxList<AttributeListSyntax> attributeLists,
     SyntaxTokenList modifiers,
     SyntaxToken identifier,
     ParameterListSyntax parameterList,
     ArrowExpressionClauseSyntax expressionBody)
     => DestructorDeclaration(
         attributeLists,
         modifiers,
         SyntaxFactory.Token(SyntaxKind.TildeToken),
         identifier,
         parameterList,
         default(BlockSyntax),
         expressionBody,
         default(SyntaxToken));
开发者ID:XieShuquan,项目名称:roslyn,代码行数:15,代码来源:DestructorDeclarationSyntax.cs

示例15: ProcessAttribute

        protected void ProcessAttribute(SyntaxNodeAnalysisContext context, SyntaxTokenList textTokens)
        {
            var token = textTokens.First();

            if (token.Span.Length >= 2)
            {
                var text = token.Text;

                if (text[1] == ':')
                {
                    var location = Location.Create(token.SyntaxTree, textTokens.Span);
                    context.ReportDiagnostic(Diagnostic.Create(Rule, location, text.Substring(0, 2)));
                }
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:15,代码来源:DoNotUseVerbatimCrefsAnalyzer.cs


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