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


C# Syntax.SyntaxList类代码示例

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


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

示例1: VisitBlock

            public override SyntaxNode VisitBlock(BlockSyntax node)
            {
                BlockSyntax block = (BlockSyntax)base.VisitBlock(node);
                SyntaxList<StatementSyntax> curList = new SyntaxList<StatementSyntax>();
                Dictionary<string, SyntaxNode> replacements = new Dictionary<string, SyntaxNode>();

                int numbering = 1;
                foreach (var stmt in block.Statements)
                {
                    SyntaxList<StatementSyntax> preList = new SyntaxList<StatementSyntax>();
                    var stm = stmt.ReplaceNodes(nodes: stmt.DescendantNodes().Reverse(), computeReplacementNode: (original, origWithReplacedDesc) =>
                    {
                        Console.WriteLine(origWithReplacedDesc.GetType() + ": " + origWithReplacedDesc);

                        if (origWithReplacedDesc.IsKind(SyntaxKind.InvocationExpression)
                            || origWithReplacedDesc.IsKind(SyntaxKind.ObjectCreationExpression))
                        {
                            return SimplifyMethodAndConstructorInvocation(ref numbering, ref preList, original, origWithReplacedDesc);
                        }
                        return origWithReplacedDesc;
                    });
                    curList = curList.AddRange(preList);
                    curList = curList.Add(stm);
                }
                return block.WithStatements(curList);
            }
开发者ID:TubaKayaDev,项目名称:Call-Graph-Builder-DotNet,代码行数:26,代码来源:MethodSimpifier.cs

示例2: ComputeFixesAsync

        public sealed override async Task ComputeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
                             
            var diagnostic = context.Diagnostics.First();
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var token = root.FindToken(diagnosticSpan.Start);

            if (token.IsKind(SyntaxKind.CatchKeyword))
            {
                var catchBlock = (CatchClauseSyntax)token.Parent;
                var tryStmt = (TryStatementSyntax)catchBlock.Parent;

                var throwStatement = SyntaxFactory.ThrowStatement();
                var newStatements = new SyntaxList<StatementSyntax>().Add(throwStatement);
                var newBlock = SyntaxFactory.Block().WithStatements(newStatements);
                var newCatchBlock = SyntaxFactory.CatchClause().WithBlock(newBlock).WithAdditionalAnnotations(Formatter.Annotation);

                var newRoot = root.ReplaceNode(catchBlock, newCatchBlock);

                context.RegisterFix(
                    CodeAction.Create("throw", context.Document.WithSyntaxRoot(newRoot)),
                    diagnostic);
            }
        }
开发者ID:julid29,项目名称:confsamples,代码行数:26,代码来源:CodeFixProvider.cs

示例3: MultiLineElement

 public static XmlElementSyntax MultiLineElement(XmlNameSyntax name, string newLineText, SyntaxList<XmlNodeSyntax> content)
 {
     return SyntaxFactory.XmlElement(
         SyntaxFactory.XmlElementStartTag(name),
         content.Insert(0, NewLine(newLineText)).Add(NewLine(newLineText)),
         SyntaxFactory.XmlElementEndTag(name));
 }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:XmlSyntaxFactory.cs

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

示例5: CheckUsingDeclarations

        private static void CheckUsingDeclarations(SyntaxNodeAnalysisContext context, SyntaxList<UsingDirectiveSyntax> usingDirectives)
        {
            UsingDirectiveSyntax lastStaticUsingDirective = null;

            foreach (var usingDirective in usingDirectives)
            {
                if (usingDirective.IsPrecededByPreprocessorDirective())
                {
                    lastStaticUsingDirective = null;
                }

                if (usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
                {
                    if (lastStaticUsingDirective != null)
                    {
                        var firstName = lastStaticUsingDirective.Name.ToNormalizedString();
                        var secondName = usingDirective.Name.ToNormalizedString();

                        if (CultureInfo.InvariantCulture.CompareInfo.Compare(firstName, secondName, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth) > 0)
                        {
                            context.ReportDiagnostic(Diagnostic.Create(Descriptor, lastStaticUsingDirective.GetLocation(), new[] { firstName, secondName }));
                            return;
                        }
                    }

                    lastStaticUsingDirective = usingDirective;
                }
            }
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:29,代码来源:SA1217UsingStaticDirectivesMustBeOrderedAlphabetically.cs

示例6: TryGetThreadStaticAttribute

        private static bool TryGetThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel, out AttributeSyntax threadStaticAttribute)
        {
            threadStaticAttribute = null;

            if (!attributeLists.Any())
            {
                return false;
            }

            foreach (var attributeList in attributeLists)
            {
                foreach (var attribute in attributeList.Attributes)
                {
                    var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                    if (attributeType != null &&
                        attributeType.ToDisplayString() == ThreadStaticAttributeName)
                    {
                        threadStaticAttribute = attribute;
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:26,代码来源:ThreadStaticNonStaticField.cs

示例7: Element

 public static XmlElementSyntax Element(XmlNameSyntax name, SyntaxList<XmlNodeSyntax> content)
 {
     return SyntaxFactory.XmlElement(
         SyntaxFactory.XmlElementStartTag(name),
         content,
         SyntaxFactory.XmlElementEndTag(name));
 }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:XmlSyntaxFactory.cs

示例8: ProcessUsings

        private static void ProcessUsings(SyntaxNodeAnalysisContext context, SyntaxList<UsingDirectiveSyntax> usings)
        {
            var usingDirectives = new List<UsingDirectiveSyntax>();
            var systemUsingDirectives = new List<UsingDirectiveSyntax>();

            foreach (var usingDirective in usings)
            {
                if (IsAliasOrStaticUsingDirective(usingDirective))
                {
                    continue;
                }

                if (usingDirective.IsPrecededByPreprocessorDirective())
                {
                    CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
                    CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
                    usingDirectives.Clear();
                    systemUsingDirectives.Clear();
                }

                if (HasNamespaceAliasQualifier(usingDirective) || !usingDirective.IsSystemUsingDirective())
                {
                    usingDirectives.Add(usingDirective);
                }
                else
                {
                    systemUsingDirectives.Add(usingDirective);
                }
            }

            CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, usingDirectives);
            CheckIncorrectlyOrderedUsingsAndReportDiagnostic(context, systemUsingDirectives);
        }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:33,代码来源:SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace.cs

示例9: ProcessUsingsAndReportDiagnostic

        private static void ProcessUsingsAndReportDiagnostic(SyntaxList<UsingDirectiveSyntax> usings, SyntaxNodeAnalysisContext context)
        {
            string systemUsingDirectivesShouldBeBeforeThisName = null;
            for (var i = 1; i < usings.Count; i++)
            {
                var usingDirective = usings[i];

                if (usingDirective.Alias != null || !usingDirective.StaticKeyword.IsKind(SyntaxKind.None) || usingDirective.IsPrecededByPreprocessorDirective())
                {
                    continue;
                }

                if (usingDirective.IsSystemUsingDirective())
                {
                    if (systemUsingDirectivesShouldBeBeforeThisName != null)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, usingDirective.GetLocation(), usingDirective.Name.ToNormalizedString(), systemUsingDirectivesShouldBeBeforeThisName));
                        continue;
                    }

                    var previousUsing = usings[i - 1];

                    if (!previousUsing.IsSystemUsingDirective() || previousUsing.StaticKeyword.Kind() != SyntaxKind.None)
                    {
                        systemUsingDirectivesShouldBeBeforeThisName = previousUsing.Name.ToNormalizedString();
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, usingDirective.GetLocation(), usingDirective.Name.ToNormalizedString(), systemUsingDirectivesShouldBeBeforeThisName));
                    }
                }
            }
        }
开发者ID:hvanbakel,项目名称:StyleCopAnalyzers,代码行数:30,代码来源:SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives.cs

示例10: Sort

 internal static SyntaxList<UsingDirectiveSyntax> Sort(SyntaxList<UsingDirectiveSyntax> directives) =>
     SyntaxFactory.List(
         directives.
             OrderBy(x => x.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) ? 1 : x.Alias == null ? 0 : 2).
             ThenBy(x => x.Alias?.ToString()).
             ThenBy(x => x.Name.ToString())
             .Distinct(new AutoRest.Core.Utilities.EqualityComparer<UsingDirectiveSyntax>((a, b) => a.Name.ToString() == b.Name.ToString(), a=> 0 )));
开发者ID:devigned,项目名称:autorest,代码行数:7,代码来源:AddUsingsRewriter.cs

示例11: MakeInterfaceSyntaxList

 private static SyntaxList<MemberDeclarationSyntax> MakeInterfaceSyntaxList(IEnumerable<MemberDeclarationSyntax> members)
 {
     var newMembers = ExtractInterfaceMembers(members).ToArray();
     var syntaxList = new SyntaxList<MemberDeclarationSyntax>();
     syntaxList = syntaxList.AddRange(newMembers);
     return syntaxList;
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:7,代码来源:ClassToInterfaceReplacement.cs

示例12: ComputeRefactoringsAsync

        public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var document = context.Document;
            if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
                return;
            var span = context.Span;
            if (!span.IsEmpty)
                return;
            var cancellationToken = context.CancellationToken;
            if (cancellationToken.IsCancellationRequested)
                return;
            var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
            if (model.IsFromGeneratedCode(cancellationToken))
                return;
            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
            var token = root.FindToken(span.Start);
            var parameter = token.Parent as ParameterSyntax;

            if (parameter != null)
            {
                var ctor = parameter.Parent.Parent as ConstructorDeclarationSyntax;
                if (ctor == null)
                    return;

                context.RegisterRefactoring(
                    CodeActionFactory.Create(
                        parameter.Span,
                        DiagnosticSeverity.Info,
                        GettextCatalog.GetString("Initialize auto-property from parameter"),
                        t2 =>
                        {
                            var propertyName = GetPropertyName(parameter.Identifier.ToString());
                            var accessorDeclList = new SyntaxList<AccessorDeclarationSyntax>().Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))).Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)));
                            var newProperty = SyntaxFactory.PropertyDeclaration(parameter.Type, propertyName)
                                .WithAccessorList(SyntaxFactory.AccessorList(accessorDeclList))
                                .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
                                .WithAdditionalAnnotations(Formatter.Annotation);

                            var assignmentStatement = SyntaxFactory.ExpressionStatement(
                                SyntaxFactory.AssignmentExpression(
                                    SyntaxKind.SimpleAssignmentExpression,
                                    propertyName != parameter.Identifier.ToString() ? (ExpressionSyntax)SyntaxFactory.IdentifierName(propertyName) : SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName(parameter.Identifier)),
                                    SyntaxFactory.IdentifierName(parameter.Identifier)
                                )
                            ).WithAdditionalAnnotations(Formatter.Annotation);

                            root = root.TrackNodes(ctor);
                            var newRoot = root.InsertNodesBefore(root.GetCurrentNode(ctor), new List<SyntaxNode>() {
                                newProperty
                            });
                            newRoot = newRoot.ReplaceNode(newRoot.GetCurrentNode(ctor), ctor.WithBody(
                                ctor.Body.WithStatements(SyntaxFactory.List<StatementSyntax>(new[] { assignmentStatement }.Concat(ctor.Body.Statements)))
                            ));

                            return Task.FromResult(document.WithSyntaxRoot(newRoot));
                        })
                );
            }
        }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:59,代码来源:InitializeAutoPropertyFromConstructorParameterCodeRefactoringProvider.cs

示例13: TrouverAssignations

 /// <summary>
 /// Retourne les assignations dans une listes d'expressions.
 /// </summary>
 /// <param name="expressions">Liste d'expressions.</param>
 /// <param name="modèleSémantique">Modèle sémantique.</param>
 /// <returns>La liste d'assignations.</returns>
 public static IEnumerable<StatementSyntax> TrouverAssignations(SyntaxList<StatementSyntax> expressions, SemanticModel modèleSémantique) =>
     expressions.Where(e =>
     {
         var expression = (e as ExpressionStatementSyntax)?.Expression as AssignmentExpressionSyntax;
         return expression?.Kind() == SyntaxKind.SimpleAssignmentExpression
             && modèleSémantique.GetSymbolInfo(expression.Left).Symbol?.Kind == SymbolKind.Field
             && modèleSémantique.GetSymbolInfo(expression.Right).Symbol?.Kind == SymbolKind.Parameter;
     });
开发者ID:JabX,项目名称:controle-point-virgule,代码行数:14,代码来源:Partagé.cs

示例14: caseStatement

        private static StatementSyntax caseStatement(SyntaxList<StatementSyntax> statements)
        {
            Debug.Assert(statements.Any());

            if (statements.Count == 1)
                return statements.First();

            return CSharp.Block(statements);
        }
开发者ID:mpmedia,项目名称:Excess,代码行数:9,代码来源:Match.cs

示例15: AttributeListList

 public static SyntaxList<AttributeListSyntax> AttributeListList(params AttributeSyntax[] attributes)
 {
     var list = new SyntaxList<AttributeListSyntax>();
     foreach (AttributeSyntax attributeSyntax in attributes)
     {
         list = list.Add(AttributeList(attributeSyntax));
     }
     return list;
 }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:9,代码来源:AttributeUtils.cs


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