本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ForStatementSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ForStatementSyntax类的具体用法?C# ForStatementSyntax怎么用?C# ForStatementSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForStatementSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ForStatementSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HasAcceptableIncrementors
static bool HasAcceptableIncrementors(ForStatementSyntax @for)
{
if (@for.Incrementors.Count != 1) return false;
var unary = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;
if (unary == null) return false;
return unary.IsKind(SyntaxKind.PostIncrementExpression) || unary.IsKind(SyntaxKind.PostDecrementExpression);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:7,代码来源:InvertForAnalyzer.cs
示例2: AreDeclarationConditionAndIncrementorUsingTheSameVariable
static bool AreDeclarationConditionAndIncrementorUsingTheSameVariable(ForStatementSyntax @for)
{
SyntaxToken reference;
if (@for.Declaration != null)
{
reference = @for.Declaration.Variables[0].Identifier;
}
else
{
var initializer = @for.Initializers[0] as AssignmentExpressionSyntax;
if (initializer == null) return false;
var name = initializer.Left as IdentifierNameSyntax;
if (name == null) return false;
reference = name.Identifier;
}
var condition = @for.Condition as BinaryExpressionSyntax;
var incrementor = @for.Incrementors[0] as PostfixUnaryExpressionSyntax;
if (!(condition.Left is IdentifierNameSyntax)) return false;
if (!(incrementor.Operand is IdentifierNameSyntax)) return false;
var conditionVariableIdentifier = (condition.Left as IdentifierNameSyntax).Identifier;
var incrementorVariableIdentifier = (incrementor.Operand as IdentifierNameSyntax).Identifier;
return reference.Text == conditionVariableIdentifier.Text
&& reference.Text == incrementorVariableIdentifier.Text;
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:29,代码来源:InvertForAnalyzer.cs
示例3: BindForParts
private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
{
BoundStatement initializer;
if (node.Declaration != null)
{
Debug.Assert(node.Initializers.Count == 0);
if (node.Declaration.IsDeconstructionDeclaration)
{
initializer = originalBinder.BindDeconstructionDeclaration(node.Declaration, node.Declaration, diagnostics);
}
else
{
ImmutableArray<BoundLocalDeclaration> unused;
initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.ForInitializerVariable, diagnostics, out unused);
}
}
else
{
initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
}
var condition = (node.Condition != null) ? originalBinder.BindBooleanExpression(node.Condition, diagnostics) : null;
var increment = originalBinder.BindStatementExpressionList(node.Incrementors, diagnostics);
var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);
Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
return new BoundForStatement(node,
this.Locals,
initializer,
condition,
increment,
body,
this.BreakLabel,
this.ContinueLabel);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:35,代码来源:ForLoopBinder.cs
示例4: AddBraces
public static ForStatementSyntax AddBraces(ForStatementSyntax forStatement)
{
Debug.Assert(forStatement != null && NeedsBraces(forStatement));
return forStatement
.WithStatement(SyntaxFactory.Block(forStatement.Statement))
.WithAdditionalAnnotations(Formatter.Annotation);
}
开发者ID:modulexcite,项目名称:StylishCode,代码行数:8,代码来源:StyleHelpers.cs
示例5: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (node.Condition != null)
{
_builder.Add(node);
}
base.VisitForStatement(node);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:LocalVariableDeclaratorsCollector.cs
示例6: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (!(node.Statement is BlockSyntax))
{
CreateAuditVariable(node.Statement);
}
base.VisitForStatement(node);
}
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:9,代码来源:AuditVariablesWalker.cs
示例7: HasConditionCompatibleWithTheIncrementor
static bool HasConditionCompatibleWithTheIncrementor(ForStatementSyntax @for)
{
var condition = @for.Condition as BinaryExpressionSyntax;
var postIncrement = IsPostIncrement(@for.Incrementors[0]);
return condition != null &&
(
(postIncrement && condition.OperatorToken.IsKind(SyntaxKind.LessThanToken)) ||
(!postIncrement && condition.OperatorToken.IsKind(SyntaxKind.GreaterThanEqualsToken))
);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:10,代码来源:InvertForAnalyzer.cs
示例8: ForInitializerBlock
internal ForInitializerBlock(ForStatementSyntax forNode, Block successor)
: base(successor)
{
if (forNode == null)
{
throw new ArgumentNullException(nameof(forNode));
}
ForNode = forNode;
}
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:10,代码来源:ForInitializerBlock.cs
示例9: ForStatement
public static string ForStatement(ForStatementSyntax statement)
{
var output = "for ";
output += SyntaxNode(statement.Declaration) + "; " + SyntaxNode(statement.Condition) + "; " + //TODO: these semicolons should be handled in their syntaxParsers
SyntaxNode(statement.Incrementors.First()).TrimEnd(); //TODO: handle multiple incrementors
output += " " + SyntaxNode(statement.Statement);
return output;
}
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:10,代码来源:LoopSyntaxParser.cs
示例10: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
if (node.Declaration != null)
{
AddVariableExpressions(node.Declaration.Variables, _expressions);
}
node.Initializers.Do(i => AddExpressionTerms(i, _expressions));
AddExpressionTerms(node.Condition, _expressions);
node.Incrementors.Do(i => AddExpressionTerms(i, _expressions));
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:CSharpProximityExpressionsService.RelevantExpressionsCollector.cs
示例11: VisitForStatement
public override void VisitForStatement(ForStatementSyntax forStatement)
{
var initializers = string.Join(" ", forStatement.Initializers.Select(o => o.ToString()));
var condition = forStatement.Condition?.ToString();
var interator = string.Join(" ", forStatement.Incrementors.Select(o => o.ToString()));
var expression = $"for ({initializers}; {condition}; {interator})";
var token = CreateBlock(expression, SDNodeRole.ForLoop);
_tokenList.Add(token);
VisitChildren(token.Statements, forStatement.Statement);
}
开发者ID:Geaz,项目名称:sharpDox,代码行数:12,代码来源:CSharpMethodVisitor.cs
示例12: VisitForStatement
public override SyntaxNode VisitForStatement(ForStatementSyntax node)
{
node = (ForStatementSyntax)base.VisitForStatement(node);
if (!node.Statement.IsKind(SyntaxKind.Block))
{
this.addedAnnotations = true;
node = node.WithStatement(SyntaxFactory.Block(node.Statement));
}
return node;
}
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:12,代码来源:SA1503_IfNeedsBlockStatement.cs
示例13: ForStatementTranslation
public ForStatementTranslation(ForStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
//KeyValuePair<int, string>? a = null;
//var b = ((bool?)null)?.Equals(false) ?? true ? false ? true : false :true;
//string str = "\{ ("\{( "(\{ "{}" })" )}") }";
Condition = syntax.Condition.Get<ExpressionTranslation>(this);
Declaration = syntax.Declaration.Get<VariableDeclarationTranslation>(this);
Incrementors = syntax.Incrementors.Get<ExpressionSyntax, ExpressionTranslation>(this);
Initializers = syntax.Initializers.Get<ExpressionSyntax, ExpressionTranslation>(this);
Statement = syntax.Statement.Get<StatementTranslation>(this);
}
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:13,代码来源:ForStatementTranslation.cs
示例14: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
var tokens = new List<SyntaxToken>();
if (node.Declaration != null)
{
tokens.AddRange(node.Declaration.Variables.Select(v => v.Identifier));
}
tracker.AddIdentifiers(tokens);
Visit(node.Statement);
tracker.RemoveIdentifiers(tokens);
}
开发者ID:EkardNT,项目名称:Roslyn,代码行数:13,代码来源:LocalConflictVisitor.cs
示例15: BindForParts
private BoundForStatement BindForParts(ForStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics)
{
BoundStatement initializer;
// Declaration and Initializers are mutually exclusive.
if (_syntax.Declaration != null)
{
ImmutableArray<BoundLocalDeclaration> unused;
initializer = originalBinder.BindForOrUsingOrFixedDeclarations(node.Declaration, LocalDeclarationKind.RegularVariable, diagnostics, out unused);
}
else
{
initializer = originalBinder.BindStatementExpressionList(node.Initializers, diagnostics);
}
BoundExpression condition = null;
var innerLocals = ImmutableArray<LocalSymbol>.Empty;
ExpressionSyntax conditionSyntax = node.Condition;
if (conditionSyntax != null)
{
originalBinder = originalBinder.GetBinder(conditionSyntax);
condition = originalBinder.BindBooleanExpression(conditionSyntax, diagnostics);
innerLocals = originalBinder.GetDeclaredLocalsForScope(conditionSyntax);
}
BoundStatement increment = null;
SeparatedSyntaxList<ExpressionSyntax> incrementors = node.Incrementors;
if (incrementors.Count > 0)
{
var scopeDesignator = incrementors.First();
var incrementBinder = originalBinder.GetBinder(scopeDesignator);
increment = incrementBinder.WrapWithVariablesIfAny(scopeDesignator, incrementBinder.BindStatementExpressionList(incrementors, diagnostics));
}
var body = originalBinder.BindPossibleEmbeddedStatement(node.Statement, diagnostics);
Debug.Assert(this.Locals == this.GetDeclaredLocalsForScope(node));
return new BoundForStatement(node,
this.Locals,
initializer,
innerLocals,
condition,
increment,
body,
this.BreakLabel,
this.ContinueLabel);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:46,代码来源:ForLoopBinder.cs
示例16: ConvertToDecrementingCounterForLoopAsync
private static async Task<Document> ConvertToDecrementingCounterForLoopAsync(Document document, ForStatementSyntax @for, CancellationToken cancellationToken)
{
var condition = (BinaryExpressionSyntax)@for.Condition;
var newEndValue = @for.Declaration != null
? @for.Declaration.Variables[0].Initializer.Value
: (@for.Initializers[0] as AssignmentExpressionSyntax).Right;
var newStartValue = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, condition.Right, One);
var newDeclaration = ReplaceStartValue(@for.Declaration, newStartValue);
var newInitializers = ReplaceStartValue(@for.Initializers, newStartValue);
var newCondition = condition
.WithOperatorToken(SyntaxFactory.Token(SyntaxKind.GreaterThanEqualsToken))
.WithRight(newEndValue);
return await ReplaceForAsync(document, @for,
newDeclaration,
newInitializers,
newCondition,
cancellationToken);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:18,代码来源:InvertForCodeFixProvider.cs
示例17: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
foreach (var invocation in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(invocation).Symbol;
if (symbol!=null && symbol.IsTaskCreationMethod())
{
Logs.TempLog.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
break;
}
if (symbol != null && symbol.IsThreadStart())
{
Logs.TempLog4.Info("{0}{1}--------------------------", Document.FilePath, node.Parent.ToLog());
break;
}
}
base.VisitForStatement(node);
}
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:19,代码来源:SimplifierDetectionWalker.cs
示例18: BindFor
public BoundForStatement BindFor(ForStatementSyntax node, DiagnosticBag diagnostics)
{
var loopBinder = this.GetBinder(node);
Debug.Assert(loopBinder != null);
return loopBinder.BindForParts(diagnostics, loopBinder);
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:6,代码来源:Binder_Statements.cs
示例19: ForLoopBinder
public ForLoopBinder(Binder enclosing, ForStatementSyntax syntax)
: base(enclosing)
{
Debug.Assert(syntax != null);
_syntax = syntax;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:6,代码来源:ForLoopBinder.cs
示例20: VisitForStatement
public override void VisitForStatement(ForStatementSyntax node)
{
Debug.Assert((object)_containingMemberOrLambda == _enclosing.ContainingMemberOrLambda);
Binder binder = new ForLoopBinder(_enclosing, node);
AddToMap(node, binder);
var declaration = node.Declaration;
if (declaration != null)
{
foreach (var variable in declaration.Variables)
{
Visit(variable, binder);
}
}
else
{
foreach (var initializer in node.Initializers)
{
Visit(initializer, binder);
}
}
ExpressionSyntax condition = node.Condition;
if (condition != null)
{
binder = new ExpressionVariableBinder(condition, binder);
AddToMap(condition, binder);
Visit(condition, binder);
}
SeparatedSyntaxList<ExpressionSyntax> incrementors = node.Incrementors;
if (incrementors.Count > 0)
{
var incrementorsBinder = new ExpressionListVariableBinder(incrementors, binder);
AddToMap(incrementors.First(), incrementorsBinder);
foreach (var incrementor in incrementors)
{
Visit(incrementor, incrementorsBinder);
}
}
VisitPossibleEmbeddedStatement(node.Statement, binder);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:43,代码来源:LocalBinderFactory.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.ForStatementSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论