本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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;
}
示例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)))
));
}
示例6: GetStatementSingle
private SyntaxNode GetStatementSingle(StatementSyntax statement)
{
var block = statement as BlockSyntax;
return block == null ?
statement :
(block.Statements.Count == 1 ? block.Statements[0] : null);
}
示例7: IfThrowPrecondition
public IfThrowPrecondition(StatementSyntax ifThrowStaement, ThrowStatementSyntax throwStatement)
{
Contract.Requires(ifThrowStaement != null);
Contract.Requires(throwStatement != null);
IfThrowStaement = ifThrowStaement;
ThrowStatement = throwStatement;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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)
);
}
示例13: CheckLoop
private static void CheckLoop(SyntaxNodeAnalysisContext context, StatementSyntax statement)
{
if (IsNestedStatement(statement))
{
return;
}
CheckStatement(context, statement, "in a loop", "only once");
}
示例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);
}
示例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;
}