本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ForeachStatement类的典型用法代码示例。如果您正苦于以下问题:C# ForeachStatement类的具体用法?C# ForeachStatement怎么用?C# ForeachStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ForeachStatement类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ForeachStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
if (nameComparer.Equals(from, foreachStatement.VariableName)) {
foreachStatement.VariableName = to;
}
return base.VisitForeachStatement(foreachStatement, data);
}
示例2: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
//Looks convoluted solution not sure this is correct way to detect something of form (foreach(var t in Enum.GetValue/GetNames(...))
InvocationExpression expr = foreachStatement.Expression as InvocationExpression;
if (expr != null)
{
MemberReferenceExpression expr2 = expr.TargetObject as MemberReferenceExpression;
if (expr2 != null)
{
IdentifierExpression expr3 = expr2.TargetObject as IdentifierExpression;
if (expr3 != null && expr3.Identifier == "Enum")
{
UnlockWith(foreachStatement);
}
}
}
return base.VisitForeachStatement(foreachStatement, data);
}
示例3: VisitForeachStatement
public override object VisitForeachStatement (ForeachStatement node, object data)
{
if (node.EmbeddedStatement is EmptyStatement)
return null;
var iteratorName = GetNextIteratorName ();
Write ("var ", iteratorName, " = ");
var extType = node.Expression.AcceptVisitor (this, null);
var ctype = extType as Mono.Cecil.TypeReference;
var itype = extType as ICSharpCode.NRefactory.Ast.TypeReference;
var isArray = false;
if (ctype != null) {
isArray = ctype.FullName.IndexOf ("[]") > 0;
} else if (itype != null) {
isArray = itype.IsArrayType;
}
//Console.WriteLine ("Node: {0}", name);
if (isArray) {
var iName = GetNextIteratorName();
Write (";");
NewLine ();
Write ("for(var ",iName,"=0;", iName, " < ", iteratorName, ".length;", iName, "++)");
NewLine ();
BeginBlock ();
PushLocals ();
Write ("var ", node.VariableName, "=", iteratorName, "[", iName, "];");
NewLine ();
Locals.Add (node.VariableName, node.TypeReference);
BlockStatement block = node.EmbeddedStatement as BlockStatement;
if (block != null) {
block.AcceptChildren (this, null);
} else {
node.EmbeddedStatement.AcceptVisitor (this, null);
}
PopLocals ();
EndBlock ();
NewLine ();
} else {
Write (".", CREATE_ITERATOR_NAME, "();");
NewLine ();
Write ("while(", iteratorName, ".", ITERATOR_HAS_NEXT_NAME, "()", ") ");
BeginBlock ();
Write ("var ", node.VariableName, " = ", iteratorName, ".", ITERATOR_NEXT_NAME, ";");
NewLine ();
PushLocals ();
Locals.Add (node.VariableName, node.TypeReference);
BlockStatement block = node.EmbeddedStatement as BlockStatement;
if (block != null) {
block.AcceptChildren (this, null);
} else {
node.EmbeddedStatement.AcceptVisitor (this, null);
}
PopLocals ();
EndBlock ();
NewLine ();
}
return null;
}
示例4: TrackedVisitForeachStatement
public override object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data)
{
this.AppendIndented(string.Empty);
this.CreateInitStatement(foreachStatement);
this.AppendLine();
this.AppendIndentedLine("while enumerator.MoveNext():");
this.IncreaseIndent();
this.AppendIndentedLine(string.Concat(foreachStatement.VariableName, " = enumerator.Current"));
foreachStatement.EmbeddedStatement.AcceptVisitor(this, data);
this.DecreaseIndent();
return null;
}
示例5: AppendForeachVariableName
private void AppendForeachVariableName(ForeachStatement foreachStatement)
{
IdentifierExpression expression = foreachStatement.Expression as IdentifierExpression;
InvocationExpression invocationExpression = foreachStatement.Expression as InvocationExpression;
MemberReferenceExpression memberReferenceExpression = foreachStatement.Expression as MemberReferenceExpression;
if (expression != null)
{
this.Append(expression.Identifier);
}
else if (invocationExpression != null)
{
invocationExpression.AcceptVisitor(this, null);
}
else if (memberReferenceExpression != null)
{
memberReferenceExpression.AcceptVisitor(this, null);
}
}
示例6: TrackedVisitForeachStatement
public virtual object TrackedVisitForeachStatement(ForeachStatement foreachStatement, object data) {
return base.VisitForeachStatement(foreachStatement, data);
}
示例7: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
if (!foreachStatement.EmbeddedStatement.IsNull) {
AddVariable(foreachStatement.TypeReference,
foreachStatement.VariableName,
foreachStatement.EmbeddedStatement.StartLocation,
foreachStatement.EndLocation,
false, true,
foreachStatement.Expression,
null,
false,
foreachStatement.EmbeddedStatement.StartLocation);
}
if (foreachStatement.Expression != null) {
foreachStatement.Expression.AcceptVisitor(this, data);
}
if (foreachStatement.EmbeddedStatement == null) {
return data;
}
return foreachStatement.EmbeddedStatement.AcceptVisitor(this, data);
}
示例8: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
base.VisitForeachStatement(foreachStatement, data);
if (resolver.CompilationUnit == null)
return null;
if (foreachStatement.TypeReference.IsNull) {
ResolveResult rr = resolver.ResolveIdentifier(foreachStatement.VariableName, foreachStatement.StartLocation, ExpressionContext.Default);
if (rr != null && rr.ResolvedType != null) {
BlockStatement blockStatement = foreachStatement.EmbeddedStatement as BlockStatement;
if (blockStatement == null) {
blockStatement = new BlockStatement();
blockStatement.AddChild(foreachStatement.EmbeddedStatement);
foreachStatement.EmbeddedStatement = blockStatement;
}
string newVariableName = foreachStatement.VariableName + "_loopVariable";
ExpressionStatement st = new ExpressionStatement(
new AssignmentExpression(
new IdentifierExpression(foreachStatement.VariableName),
AssignmentOperatorType.Assign,
new IdentifierExpression(newVariableName)));
blockStatement.Children.Insert(0, st);
st.Parent = blockStatement;
foreachStatement.VariableName = newVariableName;
foreachStatement.TypeReference = ConvertType(rr.ResolvedType);
}
}
return null;
}
示例9: VisitStatement
public void VisitStatement (ForeachStatement statement, MethodProperties meth)
{
meth.CyclometricComplexity++;
VisitExpression(((ForeachStatement)(statement)).Expression, meth);
VisitExpression(statement.NextExpression, meth);
foreach(var innerStatement in ((ForeachStatement)statement).EmbeddedStatement.Children)
VisitStatement((Statement)innerStatement, meth);
}
示例10: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
return base.VisitForeachStatement(foreachStatement, true);
}
示例11: VisitForeachStatement
public virtual bool VisitForeachStatement(ForeachStatement foreachStatement, object d)
{
if ((foreachStatement == null)) {
return SetFailure();
}
if ((d == null)) {
return SetFailure();
}
if ((foreachStatement.TypeReference == null)) {
return SetFailure();
}
if ((foreachStatement.Expression == null)) {
return SetFailure();
}
if ((foreachStatement.NextExpression == null)) {
return SetFailure();
}
if ((foreachStatement.EmbeddedStatement == null)) {
return SetFailure();
}
if(foreachStatement.GetType() != d.GetType()) {return SetFailure();}
var data = (ForeachStatement)d;
if (!IsMatch(foreachStatement, data)) {
return SetFailure();
}
foreachStatement.TypeReference.AcceptVisitor(this, data.TypeReference);
foreachStatement.Expression.AcceptVisitor(this, data.Expression);
foreachStatement.NextExpression.AcceptVisitor(this, data.NextExpression);
return foreachStatement.EmbeddedStatement.AcceptVisitor(this, data.EmbeddedStatement);
}
示例12: IsMatch
private bool IsMatch(ForeachStatement left, ForeachStatement right)
{
return left.VariableName == right.VariableName;
}
示例13: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
foreachStatement.Expression.Parent = foreachStatement;
foreachStatement.TypeReference.Parent = foreachStatement;
return base.VisitForeachStatement(foreachStatement, data);
}
示例14: VisitForeachStatement
public object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
B.ForStatement fs = new B.ForStatement(GetLexicalInfo(foreachStatement));
fs.EndSourceLocation = GetLocation(foreachStatement.EndLocation);
fs.Iterator = ConvertExpression(foreachStatement.Expression);
fs.Declarations.Add(new B.Declaration(foreachStatement.VariableName, ConvertTypeReference(foreachStatement.TypeReference)));
fs.Block = ConvertBlock(foreachStatement.EmbeddedStatement);
return fs;
}
示例15: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
curBlock.Add(foreachStatement.VariableName);
return base.VisitForeachStatement(foreachStatement, data);
}