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


C# WhileStatement类代码示例

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


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

示例1: VisitWhileStatement

		public override void VisitWhileStatement(WhileStatement whileStatement)
		{
            var token = CreateBlock(string.Format("while ({0})", whileStatement.Condition.GetText()), SDNodeRole.WhileLoop);
            _tokenList.Add(token);

            VisitChildren(token.Statements, whileStatement.EmbeddedStatement);
		}
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:7,代码来源:MethodVisitor.cs

示例2: ApplyAction

		void ApplyAction(Script script, WhileStatement statement) {
			var doWhile = new DoWhileStatement {
				Condition = statement.Condition.Clone(),
				EmbeddedStatement = statement.EmbeddedStatement.Clone()
			};

			script.Replace(statement, doWhile);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:8,代码来源:ConvertWhileToDoWhileLoopAction.cs

示例3: VisitWhileStatement

 public override object VisitWhileStatement(WhileStatement whileStatement, object data)
 {
     var condition = whileStatement.Condition as PrimitiveExpression;
     if (condition != null && condition.LiteralValue == "true")
     {
         UnlockWith(whileStatement);
     }
     return base.VisitWhileStatement(whileStatement, data);
 }
开发者ID:vlad2135,项目名称:strokes,代码行数:9,代码来源:InfiniteWhileLoopAchievement.cs

示例4: WhileStatementProducesEmptyWhile

        public void WhileStatementProducesEmptyWhile()
        {
            var statement = new WhileStatement();
            statement.Condition = true;
            statement.Statement = JS.Empty();

            Assert.AreEqual("true;", statement.Condition.ToString());
            Assert.AreEqual(";", statement.Statement.ToString());
            Assert.AreEqual("while(true);", statement.ToString());
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:10,代码来源:WhileStatementTests.cs

示例5: VisitWhileStatement

 public override object VisitWhileStatement(WhileStatement whileStatement, object data)
 {
     if(whileStatement.EmbeddedStatement is BlockStatement)
     {
         foreach (Statement innerstatement in (BlockStatement)whileStatement.EmbeddedStatement)
         {
             if(innerstatement is WhileStatement || innerstatement is DoWhileStatement)
                 UnlockWith(whileStatement);
         }
     }
     return base.VisitWhileStatement(whileStatement, data);
 }
开发者ID:cohenw,项目名称:strokes,代码行数:12,代码来源:NestedWhileStatementAchievement.cs

示例6: WhileStatementRequiresConditionAndStatement

        public void WhileStatementRequiresConditionAndStatement()
        {
            var statement = new WhileStatement();

            Expect.Throw<InvalidOperationException>(() => statement.ToString());

            statement.Condition = true;

            Expect.Throw<InvalidOperationException>(() => statement.ToString());

            statement.Statement = JS.Empty();

            Assert.AreEqual("while(true);", statement.ToString());
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:14,代码来源:WhileStatementTests.cs

示例7: Walk

 public override object Walk(WhileStatement node)
 {
     object result = null;
     while (InterpreterHelper.IsTrue(node.Condition.Accept(this)))
     {
         try
         {
             result = node.Body.Accept(this);
         }
         catch (Break)
         {
             break;
         }
         catch (Next)
         {
             continue;
         }
     }
     return result;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:20,代码来源:Interpreter.cs

示例8: buildChunkedDelete

        private string buildChunkedDelete(DeleteSpecification delete)
        {

            var counter = new DeclareVariableStatement();
            var counterVariable = new DeclareVariableElement();
            counterVariable.DataType = new SqlDataTypeReference() {SqlDataTypeOption = SqlDataTypeOption.Int};
            counterVariable.VariableName = new Identifier() {Value = "@rowcount"};
            counterVariable.Value = new IntegerLiteral() {Value = "10000"};
            counter.Declarations.Add(counterVariable);
            
            delete.TopRowFilter = new TopRowFilter();
            delete.TopRowFilter.Expression = new ParenthesisExpression() {Expression = new IntegerLiteral() {Value = "10000"} };

            var setCounter = new SetVariableStatement();
            setCounter.Variable = new VariableReference() {Name = "@rowcount"};
            setCounter.Expression = new GlobalVariableExpression() {Name = "@@rowcount"};
            setCounter.AssignmentKind = AssignmentKind.Equals;

            var deleteStatement = new DeleteStatement();
            deleteStatement.DeleteSpecification = delete;

            var beginEnd = new BeginEndBlockStatement();
            beginEnd.StatementList = new StatementList();
            beginEnd.StatementList.Statements.Add(deleteStatement);
            beginEnd.StatementList.Statements.Add(setCounter);

            var whilePredicate = new BooleanComparisonExpression();
            whilePredicate.ComparisonType = BooleanComparisonType.GreaterThan;
            whilePredicate.FirstExpression = new VariableReference() {Name = "@rowcount"};
            whilePredicate.SecondExpression = new IntegerLiteral() {Value = "0"};

            var whileStatement = new WhileStatement();
            whileStatement.Predicate = whilePredicate;
            whileStatement.Statement = beginEnd;
            
            var text = ScriptDom.GenerateTSql(counter) + "\r\n" + ScriptDom.GenerateTSql(whileStatement);

            return text;
        }
开发者ID:japj,项目名称:SSDT-DevPack,代码行数:39,代码来源:ChunkDeletesRewriter.cs

示例9: Visit

			public override object Visit (While whileStatement)
			{
				var result = new WhileStatement (WhilePosition.Begin);
				var location = LocationsBag.GetLocations (whileStatement);
				result.AddChild (new CSharpTokenNode (Convert (whileStatement.loc), "while".Length), WhileStatement.WhileKeywordRole);
				
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), WhileStatement.Roles.LPar);
				result.AddChild ((INode)whileStatement.expr.Accept (this), WhileStatement.Roles.Condition);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.RPar);
				result.AddChild ((INode)whileStatement.Statement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
				
				return result;
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:15,代码来源:CSharpParser.cs

示例10: VisitWhileStatement

		public virtual void VisitWhileStatement (WhileStatement whileStatement)
		{
			VisitChildren (whileStatement);
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs

示例11: PostWalk

 public override void PostWalk(WhileStatement node) { }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:1,代码来源:PythonWalker.Generated.cs

示例12: TransformNode

		IEnumerable<Statement> TransformNode(ILNode node)
		{
			if (node is ILLabel) {
				yield return new Ast.LabelStatement { Label = ((ILLabel)node).Name };
			} else if (node is ILExpression) {
				List<ILRange> ilRanges = ILRange.OrderAndJoint(node.GetSelfAndChildrenRecursive<ILExpression>().SelectMany(e => e.ILRanges));
				AstNode codeExpr = TransformExpression((ILExpression)node);
				if (codeExpr != null) {
					codeExpr = codeExpr.WithAnnotation(ilRanges);
					if (codeExpr is Ast.Expression) {
						yield return new Ast.ExpressionStatement { Expression = (Ast.Expression)codeExpr };
					} else if (codeExpr is Ast.Statement) {
						yield return (Ast.Statement)codeExpr;
					} else {
						throw new Exception();
					}
				}
			} else if (node is ILWhileLoop) {
				ILWhileLoop ilLoop = (ILWhileLoop)node;
				WhileStatement whileStmt = new WhileStatement() {
					Condition = ilLoop.Condition != null ? (Expression)TransformExpression(ilLoop.Condition) : new PrimitiveExpression(true),
					EmbeddedStatement = TransformBlock(ilLoop.BodyBlock)
				};
				yield return whileStmt;
			} else if (node is ILCondition) {
				ILCondition conditionalNode = (ILCondition)node;
				bool hasFalseBlock = conditionalNode.FalseBlock.EntryGoto != null || conditionalNode.FalseBlock.Body.Count > 0;
				yield return new Ast.IfElseStatement {
					Condition = (Expression)TransformExpression(conditionalNode.Condition),
					TrueStatement = TransformBlock(conditionalNode.TrueBlock),
					FalseStatement = hasFalseBlock ? TransformBlock(conditionalNode.FalseBlock) : null
				};
			} else if (node is ILSwitch) {
				ILSwitch ilSwitch = (ILSwitch)node;
				SwitchStatement switchStmt = new SwitchStatement() { Expression = (Expression)TransformExpression(ilSwitch.Condition) };
				foreach (var caseBlock in ilSwitch.CaseBlocks) {
					SwitchSection section = new SwitchSection();
					if (caseBlock.Values != null) {
						section.CaseLabels.AddRange(caseBlock.Values.Select(i => new CaseLabel() { Expression = AstBuilder.MakePrimitive(i, ilSwitch.Condition.InferredType) }));
					} else {
						section.CaseLabels.Add(new CaseLabel());
					}
					section.Statements.Add(TransformBlock(caseBlock));
					switchStmt.SwitchSections.Add(section);
				}
				yield return switchStmt;
			} else if (node is ILTryCatchBlock) {
				ILTryCatchBlock tryCatchNode = ((ILTryCatchBlock)node);
				var tryCatchStmt = new Ast.TryCatchStatement();
				tryCatchStmt.TryBlock = TransformBlock(tryCatchNode.TryBlock);
				foreach (var catchClause in tryCatchNode.CatchBlocks) {
					if (catchClause.ExceptionVariable == null
					    && (catchClause.ExceptionType == null || catchClause.ExceptionType.MetadataType == MetadataType.Object))
					{
						tryCatchStmt.CatchClauses.Add(new Ast.CatchClause { Body = TransformBlock(catchClause) });
					} else {
						tryCatchStmt.CatchClauses.Add(
							new Ast.CatchClause {
								Type = AstBuilder.ConvertType(catchClause.ExceptionType),
								VariableName = catchClause.ExceptionVariable == null ? null : catchClause.ExceptionVariable.Name,
								Body = TransformBlock(catchClause)
							});
					}
				}
				if (tryCatchNode.FinallyBlock != null)
					tryCatchStmt.FinallyBlock = TransformBlock(tryCatchNode.FinallyBlock);
				if (tryCatchNode.FaultBlock != null) {
					CatchClause cc = new CatchClause();
					cc.Body = TransformBlock(tryCatchNode.FaultBlock);
					cc.Body.Add(new ThrowStatement()); // rethrow
					tryCatchStmt.CatchClauses.Add(cc);
				}
				yield return tryCatchStmt;
			} else if (node is ILFixedStatement) {
				ILFixedStatement fixedNode = (ILFixedStatement)node;
				FixedStatement fixedStatement = new FixedStatement();
				foreach (ILExpression initializer in fixedNode.Initializers) {
					Debug.Assert(initializer.Code == ILCode.Stloc);
					ILVariable v = (ILVariable)initializer.Operand;
					fixedStatement.Variables.Add(
						new VariableInitializer {
							Name = v.Name,
							Initializer = (Expression)TransformExpression(initializer.Arguments[0])
						}.WithAnnotation(v));
				}
				fixedStatement.Type = AstBuilder.ConvertType(((ILVariable)fixedNode.Initializers[0].Operand).Type);
				fixedStatement.EmbeddedStatement = TransformBlock(fixedNode.BodyBlock);
				yield return fixedStatement;
			} else if (node is ILBlock) {
				yield return TransformBlock((ILBlock)node);
			} else {
				throw new Exception("Unknown node type");
			}
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:94,代码来源:AstMethodBodyBuilder.cs

示例13: Exit

 public override void Exit(WhileStatement node)
 {
     level--;
 }
开发者ID:buunguyen,项目名称:bike,代码行数:4,代码来源:PrintNodeWalker.cs

示例14: GenerateWhileStatement

        /// <summary>
        ///     Generates the code for a WhileStatement node.
        /// </summary>
        /// <param name="ws">The WhileStatement node.</param>
        /// <returns>String containing C# code for WhileStatement ws.</returns>
        private string GenerateWhileStatement(WhileStatement ws)
        {
            StringBuilder retVal = new StringBuilder();
            StringBuilder tmpVal = new StringBuilder();

            bool marc = FuncCallsMarc();

            tmpVal.Append(GenerateIndented("while (", ws));
            tmpVal.Append(GenerateNode((SYMBOL) ws.kids.Pop()));
            tmpVal.Append(GenerateLine(")"));

            //Forces all functions to use MoveNext() instead of .Current, as it never changes otherwise, and the loop runs infinitely
            m_isInEnumeratedDeclaration = true;
            retVal.Append(DumpFunc(marc));
            retVal.Append(tmpVal.ToString());
            m_isInEnumeratedDeclaration = false; //End above

            if (IsParentEnumerable)
            {
                retVal.Append(GenerateLine("{")); // SLAM! No 'while(true) doThis(); ' statements for you!
                retVal.Append(GenerateLine("if (CheckSlice()) yield return null;"));
            }

            // CompoundStatement handles indentation itself but we need to do it
            // otherwise.
            bool indentHere = ws.kids.Top is Statement;
            if (indentHere) m_braceCount++;
            retVal.Append(GenerateNode((SYMBOL) ws.kids.Pop()));
            if (indentHere) m_braceCount--;

            if (IsParentEnumerable)
                retVal.Append(GenerateLine("}"));

            return retVal.ToString() + DumpAfterFunc(marc);
        }
开发者ID:velus,项目名称:Async-Sim-Testing,代码行数:40,代码来源:CSCodeGenerator.cs

示例15: VisitWhileStatement

		public override void VisitWhileStatement(WhileStatement whileStatement) {
			// Condition
			JsExpression condition;
			List<JsStatement> preBody = null;
			var compiledCondition = CompileExpression(whileStatement.Condition, CompileExpressionFlags.ReturnValueIsImportant);
			if (compiledCondition.AdditionalStatements.Count == 0) {
				condition = compiledCondition.Expression;
			}
			else {
				// The condition requires additional statements. Transform "while ((SomeProperty = 1) < 0) { ... }" to "while (true) { this.set_SomeProperty(1); if (!(i < 1)) { break; } ... }
				preBody = new List<JsStatement>();
				preBody.AddRange(compiledCondition.AdditionalStatements);
				preBody.Add(JsStatement.If(JsExpression.LogicalNot(compiledCondition.Expression), JsStatement.Break(), null));
				condition = JsExpression.True;
			}

			var body = CreateInnerCompiler().Compile(whileStatement.EmbeddedStatement);
			if (preBody != null)
				body = JsStatement.Block(preBody.Concat(body.Statements));

			_result.Add(JsStatement.While(condition, body));
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:22,代码来源:StatementCompiler.cs


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