本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ForEachStatementSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ForEachStatementSyntax类的具体用法?C# ForEachStatementSyntax怎么用?C# ForEachStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForEachStatementSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ForEachStatementSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitForEachStatement
public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
{
if (node.Identifier.ToString() == renameFrom.ToString())
node = node.WithIdentifier(renameTo);
return base.VisitForEachStatement(node);
}
示例2: VisitForEachStatement
public override void VisitForEachStatement(ForEachStatementSyntax foreachStatement)
{
var expression = $"foreach ({foreachStatement.Type} {foreachStatement.Identifier} in {foreachStatement.InKeyword})";
var token = CreateBlock(expression, SDNodeRole.ForEach);
_tokenList.Add(token);
VisitChildren(token.Statements, foreachStatement.Statement);
}
示例3: AddBraces
public static ForEachStatementSyntax AddBraces(ForEachStatementSyntax forEachStatement)
{
Debug.Assert(forEachStatement != null && NeedsBraces(forEachStatement));
return forEachStatement
.WithStatement(SyntaxFactory.Block(forEachStatement.Statement))
.WithAdditionalAnnotations(Formatter.Annotation);
}
示例4: VisitForEachStatement
public override void VisitForEachStatement(ForEachStatementSyntax node)
{
if (!(node.Statement is BlockSyntax))
{
CreateAuditVariable(node.Statement);
}
base.VisitForEachStatement(node);
}
示例5: ForeachCollectionProducerBlock
internal ForeachCollectionProducerBlock(ForEachStatementSyntax foreachNode, Block successor)
: base(successor)
{
if (foreachNode == null)
{
throw new ArgumentNullException(nameof(foreachNode));
}
ForeachNode = foreachNode;
}
示例6: VisitForEachStatement
public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
{
node = (ForEachStatementSyntax)base.VisitForEachStatement(node);
if (!node.Statement.IsKind(SyntaxKind.Block))
{
this.addedAnnotations = true;
node = node.WithStatement(SyntaxFactory.Block(node.Statement));
}
return node;
}
示例7: CalculateNewRoot
private static SyntaxNode CalculateNewRoot(SyntaxNode root, ForEachStatementSyntax foreachSyntax, SemanticModel semanticModel)
{
var collection = foreachSyntax.Expression;
var typeName = foreachSyntax.Type.ToString();
var invocationToAdd = GetOfTypeInvocation(typeName, collection);
var namedTypes = semanticModel.LookupNamespacesAndTypes(foreachSyntax.SpanStart).OfType<INamedTypeSymbol>();
var isUsingAlreadyThere = namedTypes.Any(nt => nt.ToDisplayString() == ofTypeExtensionClass);
if (isUsingAlreadyThere)
{
return root
.ReplaceNode(collection, invocationToAdd)
.WithAdditionalAnnotations(Formatter.Annotation);
}
else
{
var usingDirectiveToAdd = SyntaxFactory.UsingDirective(
SyntaxFactory.QualifiedName(
SyntaxFactory.IdentifierName("System"),
SyntaxFactory.IdentifierName("Linq")));
var annotation = new SyntaxAnnotation("CollectionToChange");
var newRoot = root.ReplaceNode(
collection,
collection.WithAdditionalAnnotations(annotation));
var node = newRoot.GetAnnotatedNodes(annotation).First();
var closestNamespaceWithUsing = node.AncestorsAndSelf()
.OfType<NamespaceDeclarationSyntax>()
.FirstOrDefault(n => n.Usings.Count > 0);
if (closestNamespaceWithUsing != null)
{
newRoot = newRoot.ReplaceNode(
closestNamespaceWithUsing,
closestNamespaceWithUsing.AddUsings(usingDirectiveToAdd))
.WithAdditionalAnnotations(Formatter.Annotation);
}
else
{
var compilationUnit = node.FirstAncestorOrSelf<CompilationUnitSyntax>();
newRoot = compilationUnit.AddUsings(usingDirectiveToAdd);
}
node = newRoot.GetAnnotatedNodes(annotation).First();
return newRoot
.ReplaceNode(node, invocationToAdd)
.WithAdditionalAnnotations(Formatter.Annotation);
}
}
示例8: VisitForEachStatement
public override void VisitForEachStatement(ForEachStatementSyntax node)
{
foreach (var invocation in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(invocation).Symbol;
if (symbol != null && symbol.IsTaskCreationMethod())
{
Logs.TempLog2.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
break;
}
if (symbol != null && symbol.IsThreadStart())
{
Logs.TempLog5.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
break;
}
}
base.VisitForEachStatement(node);
}
示例9: TrySearchForIfThenContinueStatement
private static bool TrySearchForIfThenContinueStatement(ForEachStatementSyntax fe, out IfStatementSyntax ifStatement, out string ifType)
{
if (fe.Statement is BlockSyntax)
{
var block = ((BlockSyntax)fe.Statement);
if ((block.Statements.Count > 1 && block.Statements.First() is IfStatementSyntax) ||
(block.Statements.Count > 0 && block.Statements.First() is IfStatementSyntax && ((IfStatementSyntax)block.Statements.First()).Else != null) )
{
ifStatement = (block.Statements.FirstOrDefault() as IfStatementSyntax);
if (ifStatement?.Statement is ContinueStatementSyntax ||
((ifStatement?.Statement as BlockSyntax)?.Statements)?.FirstOrDefault() is ContinueStatementSyntax)
{
ifType = IfWithContinueToWhere;
return true;
}
}
}
ifStatement = null;
ifType = null;
return false;
}
示例10: ConvertIfToLINQ
private async Task<Document> ConvertIfToLINQ(Document document, IfStatementSyntax ifStatement, ForEachStatementSyntax foreachStatement, CancellationToken c)
{
var generator = SyntaxGenerator.GetGenerator(document);
var oldVariables = ifStatement.Condition.DescendantNodesAndSelf().OfType<IdentifierNameSyntax>().Where(x => x.Identifier.Text == foreachStatement.Identifier.Text);
var whereCall = generator.InvocationExpression(
generator.MemberAccessExpression(foreachStatement.Expression, "Where"),
generator.Argument(
generator.ValueReturningLambdaExpression(
new[] { generator.LambdaParameter("x") },
ifStatement.Condition.ReplaceNodes(oldVariables, (x, y) => generator.IdentifierName("x")))));
var root = await document.GetSyntaxRootAsync(c);
var newFeStatement = foreachStatement
.WithExpression((ExpressionSyntax)whereCall)
.WithStatement(ifStatement.Statement.WithAdditionalAnnotations(Formatter.Annotation));
var newRoot = root.ReplaceNode(foreachStatement, newFeStatement);
return document.WithSyntaxRoot(newRoot);
}
示例11: GetActiveSpan
private static TextSpan GetActiveSpan(ForEachStatementSyntax node, ForEachPart part)
{
switch (part)
{
case ForEachPart.ForEach:
return node.ForEachKeyword.Span;
case ForEachPart.VariableDeclaration:
return TextSpan.FromBounds(node.Type.SpanStart, node.Identifier.Span.End);
case ForEachPart.In:
return node.InKeyword.Span;
case ForEachPart.Expression:
return node.Expression.Span;
default:
throw ExceptionUtilities.UnexpectedValue(part);
}
}
示例12: VisitForEachStatement
public override SyntaxNode VisitForEachStatement(ForEachStatementSyntax node)
{
SyntaxNode rewrittenNode = null;
if (node.Statement != null)
rewrittenNode = RewriteWithBlockIfRequired(node, node.Statement);
return base.VisitForEachStatement((ForEachStatementSyntax)rewrittenNode ?? node);
}
示例13: GetForEachStatementInfo
public override ForEachStatementInfo GetForEachStatementInfo(ForEachStatementSyntax node)
{
MemberSemanticModel memberModel = GetMemberModel(node);
return memberModel == null ? default(ForEachStatementInfo) : memberModel.GetForEachStatementInfo(node);
}
示例14: ForEachStatementTranslation
public ForEachStatementTranslation(ForEachStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Expression = syntax.Expression.Get<ExpressionTranslation>(this);
Statement = syntax.Statement.Get<StatementTranslation>(this);
Type = syntax.Type.Get<TypeTranslation>(this);
}
示例15: AddForEachKeywordSequencePoint
/// <summary>
/// Add sequence point |here|:
///
/// |foreach| (Type var in expr) { }
/// </summary>
/// <remarks>
/// Hit once, before looping begins.
/// </remarks>
private void AddForEachKeywordSequencePoint(ForEachStatementSyntax forEachSyntax, ref BoundStatement result)
{
if (this.GenerateDebugInfo)
{
BoundSequencePointWithSpan foreachKeywordSequencePoint = new BoundSequencePointWithSpan(forEachSyntax, null, forEachSyntax.ForEachKeyword.Span);
result = new BoundStatementList(forEachSyntax, ImmutableArray.Create<BoundStatement>(foreachKeywordSequencePoint, result));
}
}