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


C# StatementSyntax类代码示例

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


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

示例1: CheckStatement

        private bool CheckStatement(SemanticModel semanticModel, StatementSyntax statement, CancellationToken cancellationToken)
        {
            if (statement is CheckedStatementSyntax ||
                statement is DoStatementSyntax ||
                statement is EmptyStatementSyntax ||
                statement is ExpressionStatementSyntax ||
                statement is FixedStatementSyntax ||
                statement is ForEachStatementSyntax ||
                statement is ForStatementSyntax ||
                statement is IfStatementSyntax ||
                statement is LocalDeclarationStatementSyntax ||
                statement is LockStatementSyntax ||
                statement is ReturnStatementSyntax ||
                statement is SwitchStatementSyntax ||
                statement is ThrowStatementSyntax ||
                statement is TryStatementSyntax ||
                statement is UnsafeStatementSyntax ||
                statement is UsingStatementSyntax ||
                statement is WhileStatementSyntax)
            {
                return true;
            }

            return false;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:25,代码来源:CSharpSelectionValidator.Validator.cs

示例2: TryGetExpression

        private static ExpressionSyntax TryGetExpression(StatementSyntax firstStatement)
        {
            if (firstStatement.Kind() == SyntaxKind.ExpressionStatement)
            {
                return ((ExpressionStatementSyntax)firstStatement).Expression;
            }
            else if (firstStatement.Kind() == SyntaxKind.ReturnStatement)
            {
                var returnStatement = (ReturnStatementSyntax)firstStatement;
                if (returnStatement.Expression != null)
                {
                    // If there are any comments on the return keyword, move them to
                    // the expression.
                    return firstStatement.GetLeadingTrivia().Any(t => t.IsSingleOrMultiLineComment())
                        ? returnStatement.Expression.WithLeadingTrivia(returnStatement.GetLeadingTrivia())
                        : returnStatement.Expression;
                }
            }
            else if (firstStatement.Kind() == SyntaxKind.ThrowStatement)
            {
                var throwStatement = (ThrowStatementSyntax)firstStatement;
                if (throwStatement.Expression != null)
                {
                    return SyntaxFactory.ThrowExpression(throwStatement.ThrowKeyword, throwStatement.Expression);
                }
            }

            return null;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:29,代码来源:BlockSyntaxExtensions.cs

示例3: GenerateStatement

        private void GenerateStatement(StatementSyntax statement)
        {
            var success = false;
            int mark = GetMark();

            switch (statement.Kind())
            {
                case SyntaxKind.LocalDeclarationStatement:
                    success = TryGenerateLocal((LocalDeclarationStatementSyntax)statement);
                    break;
                case SyntaxKind.Block:
                    success = true;
                    GenerateBlock((BlockSyntax)statement);
                    break;
                case SyntaxKind.ExpressionStatement:
                    success = TryGenerateExpressionStatement((ExpressionStatementSyntax)statement);
                    break;
            }

            if (!success)
            {
                Rewind(mark);
                GenerateUnknown(statement);
            }

            // Just for readability
            LineBreak();
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:28,代码来源:MethodXmlBuilder.cs

示例4: ControlFlowNode

 public ControlFlowNode(StatementSyntax previousStatement, StatementSyntax nextStatement, ControlFlowNodeType type)
 {
     if (previousStatement == null && nextStatement == null)
         throw new ArgumentException("previousStatement and nextStatement must not be both null");
     this.PreviousStatement = previousStatement;
     this.NextStatement = nextStatement;
     this.Type = type;
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:8,代码来源:ControlFlow.cs

示例5: AddStatementToConstructorBody

        internal static SyntaxNode AddStatementToConstructorBody(SyntaxNode root, ConstructorDeclarationSyntax constructor, StatementSyntax statement)
        {
            var body = constructor.Body ?? SyntaxFactory.Block();

            return root.ReplaceNode(root.GetCurrentNode(constructor), constructor.WithBody(
                    body.WithStatements(SyntaxFactory.List(new[] { statement }.Concat(body.Statements)))
                ));
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:8,代码来源:Manipulations.cs

示例6: GetStatementSingle

        private SyntaxNode GetStatementSingle(StatementSyntax statement)
        {
            var block = statement as BlockSyntax;

            return block == null ?
                statement :
                (block.Statements.Count == 1 ? block.Statements[0] : null);
        }
开发者ID:mytinyfast,项目名称:CSharpCodingGuidelines,代码行数:8,代码来源:AV1545.cs

示例7: IfThrowPrecondition

        public IfThrowPrecondition(StatementSyntax ifThrowStaement, ThrowStatementSyntax throwStatement)
        {
            Contract.Requires(ifThrowStaement != null);
            Contract.Requires(throwStatement != null);

            IfThrowStaement = ifThrowStaement;
            ThrowStatement = throwStatement;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:8,代码来源:PreconditionsBlock.cs

示例8: ConvertToConditional

        private Document ConvertToConditional(Document document, SemanticModel semanticModel, IfStatementSyntax ifStatement, StatementSyntax replacementStatement, CancellationToken cancellationToken)
        {
            var oldRoot = semanticModel.SyntaxTree.GetRoot();
            var newRoot = oldRoot.ReplaceNode(
                oldNode: ifStatement,
                newNode: replacementStatement.WithAdditionalAnnotations(Formatter.Annotation));

            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:CodeRefactoringProvider.cs

示例9: GetMemberAccessIdentifierFromStatements

 private static ExpressionSyntax GetMemberAccessIdentifierFromStatements(SemanticModel semanticModel, StatementSyntax statementInsideIf, StatementSyntax statementInsideElse)
 {
     var expressionIf = statementInsideIf as ExpressionStatementSyntax;
     var expressionElse = statementInsideElse as ExpressionStatementSyntax;
     var memberAccessExpression = expressionIf != null && expressionElse != null
         ? GetMemberAccessExpressionFromAssignment(semanticModel, expressionIf.Expression as AssignmentExpressionSyntax, expressionElse.Expression as AssignmentExpressionSyntax)
         : GetMemberAccessExpressionFromReturn(statementInsideIf as ReturnStatementSyntax, statementInsideElse as ReturnStatementSyntax);
     return memberAccessExpression?.Expression;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:9,代码来源:ExistenceOperatorAnalyzer.cs

示例10: MakeObjectInitializer

 private static Document MakeObjectInitializer(Document document, SyntaxNode root, StatementSyntax statement, ISymbol variableSymbol, SemanticModel semanticModel)
 {
     var blockParent = statement.FirstAncestorOrSelf<BlockSyntax>();
     var objectCreationExpression = statement.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().Single();
     var newBlockParent = CreateNewBlockParent(statement, semanticModel, objectCreationExpression, variableSymbol);
     var newRoot = root.ReplaceNode(blockParent, newBlockParent);
     var newDocument = document.WithSyntaxRoot(newRoot);
     return newDocument;
 }
开发者ID:nikolasmagno,项目名称:code-cracker,代码行数:9,代码来源:ObjectInitializerCodeFixProvider.cs

示例11: CreateSpeculative

        /// <summary>
        /// Creates a speculative SemanticModel for a method body that did not appear in the original source code.
        /// </summary>
        internal static MethodBodySemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, MethodSymbol owner, StatementSyntax syntax, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(syntax != null);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return new MethodBodySemanticModel(parentSemanticModel.Compilation, owner, rootBinder, syntax, parentSemanticModel, position);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:12,代码来源:MethodBodySemanticModel.cs

示例12: CreateSection

        private static SwitchSectionSyntax CreateSection(SwitchLabelSyntax label, StatementSyntax statement)
        {
            var labels = new SyntaxList<SwitchLabelSyntax>();
            labels = labels.Add(label);

            return SyntaxFactory.SwitchSection(
                labels, CreateSectionStatements(statement)
                );
        }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:9,代码来源:ConvertToSwitchCodeFixProvider.cs

示例13: CheckLoop

        private static void CheckLoop(SyntaxNodeAnalysisContext context, StatementSyntax statement)
        {
            if (IsNestedStatement(statement))
            {
                return;
            }

            CheckStatement(context, statement, "in a loop", "only once");
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:9,代码来源:MultilineBlocksWithoutBrace.cs

示例14: IsThrowArgumentExceptionStatement

        private static bool IsThrowArgumentExceptionStatement(StatementSyntax statement, SemanticModel semanticModel)
        {
            var throwStatement = statement as ThrowStatementSyntax;

            var objectCreation = throwStatement?.Expression as ObjectCreationExpressionSyntax;
            if (objectCreation == null) return false;

            var symbol = semanticModel.GetSymbolInfo(objectCreation.Type).Symbol;
            return symbol.IsArgumentExceptionType(semanticModel);
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:10,代码来源:PreconditionsBlock.cs

示例15: MakeBlockAsync

        private async Task<Document> MakeBlockAsync(Document document, StatementSyntax ifChildStatement, CancellationToken c)
        {
            var block = SyntaxFactory.Block(ifChildStatement);
            // Replace the old statement with the block:
            var root = await document.GetSyntaxRootAsync();
            var newRoot = root.ReplaceNode((SyntaxNode)ifChildStatement, block);

            var newDocument = document.WithSyntaxRoot(newRoot);
            return newDocument;
        }
开发者ID:Winsto,项目名称:MVA-Roslyn,代码行数:10,代码来源:IfBraceFixer.cs


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