本文整理汇总了C#中System.CodeDom.CodeIterationStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeIterationStatement类的具体用法?C# CodeIterationStatement怎么用?C# CodeIterationStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeIterationStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeIterationStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public void Visit(WhileStatement whileStatement)
{
using (Scope.Push(_mainType))
{
var tableArg = VisitChild(whileStatement.TableReference);
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "While_" + tableArg.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
GenerateCallStatement(method.Statements, whileStatement.Line.Line);
var loop = new CodeIterationStatement();
loop.InitStatement = new CodeSnippetStatement();
loop.IncrementStatement = new CodeSnippetStatement();
loop.TestExpression = new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(tableArg.CodeExpression, "RowCount"), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0));
method.Statements.Add(loop);
var blockArgs = VisitChild(whileStatement.Block, new CodeDomArg() { Tag = true });
loop.Statements.AddRange(blockArgs.ParentStatements);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_mainType.Type.Members.Add(method);
_codeStack.Peek().ParentStatements.Add(methodcall);
_codeStack.Peek().CodeExpression = methodcall;
}
}
示例2: EmitIterationStatement
void EmitIterationStatement(CodeIterationStatement Iterate)
{
Depth++;
Debug("Emitting iteration statement");
// Used for break and continue later on
var Meta = new LoopMetadata {
Begin = Generator.DefineLabel(),
End = Generator.DefineLabel(),
};
Loops.Push(Meta);
EmitStatement(Iterate.InitStatement, false);
// The beginning of our loop: check the limit
Generator.MarkLabel(Meta.Begin);
EmitExpression(Iterate.TestExpression, false);
Generator.Emit(OpCodes.Brfalse, Meta.End);
// Emit the actual statements within
EmitStatementCollection(Iterate.Statements);
// Increase the counter by one
EmitStatement(Iterate.IncrementStatement, false);
// Start all over again
Generator.Emit(OpCodes.Br, Meta.Begin);
Generator.MarkLabel(Meta.End);
Loops.Pop();
Depth--;
}
示例3: BeginLoop
public void BeginLoop()
{
var cond = new CodeBinaryOperatorExpression(_expr_memory_pointer, CodeBinaryOperatorType.IdentityInequality, _expr_value_zero);
var loop = new CodeIterationStatement(new CodeSnippetStatement(), cond, new CodeSnippetStatement());
_nest.Peek().Add(loop);
_nest.Push(loop.Statements);
IncrementInstructionPointer();
}
示例4: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeIterationStatement cis = new CodeIterationStatement ();
Assert.IsNull (cis.IncrementStatement, "IncrementStatement");
cis.IncrementStatement = new CodeStatement ();
Assert.IsNull (cis.InitStatement, "InitStatement");
cis.InitStatement = new CodeStatement ();
Assert.AreEqual (0, cis.Statements.Count, "Statements");
Assert.IsNull (cis.TestExpression, "TestExpression");
cis.TestExpression = new CodeExpression ();
}
示例5: TypescriptIterationStatement
public TypescriptIterationStatement(
IStatementFactory statementFactory,
IExpressionFactory expressionFactory,
CodeIterationStatement statement,
CodeGeneratorOptions options)
{
_statementFactory = statementFactory;
_expressionFactory = expressionFactory;
_statement = statement;
_options = options;
}
示例6: Emit
// Emit a codedome expression representing a while loop.
public static CodeStatement Emit(WhileLoop loop)
{
// A while loop is a for loop with no initializer or incrementor, only a condition.
var i = new CodeIterationStatement(new CodeSnippetStatement(""),
CodeDomEmitter.EmitCodeExpression(loop.Condition.ChildExpressions[0]),
new CodeSnippetStatement(""));
// Emit the statements found in the body of the while loop.
foreach (var e in loop.ChildExpressions)
i.Statements.Add(CodeDomEmitter.EmitCodeStatement(e));
return i;
}
示例7: Visit
public void Visit(EachStatement eachStatement)
{
using (Scope.Push(_mainType))
{
var iterationArg = VisitChild(eachStatement.IterationVariable);
var tableArg = VisitChild(eachStatement.TableReference);
var rowType = iterationArg.Scope.CodeDomReference;
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "Each_" + iterationArg.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
GenerateCallStatement(method.Statements, eachStatement.Line.Line);
var progressInc = new CodeAssignStatement(new CodePropertyReferenceExpression(null, "TotalOperations"),
new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(null, "TotalOperations"),
CodeBinaryOperatorType.Add,
new CodePropertyReferenceExpression(tableArg.CodeExpression, "RowCount"))
);
method.Statements.Add(progressInc);
method.Statements.Add(
new CodeVariableDeclarationStatement(new CodeTypeReference("IEnumerator", rowType),
"x",
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(tableArg.CodeExpression, "GetCopyEnumerator",
null)))
);
var loop = new CodeIterationStatement();
loop.InitStatement = new CodeSnippetStatement();
loop.IncrementStatement = new CodeSnippetStatement();
loop.TestExpression = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(new CodeTypeReferenceExpression("x"), "MoveNext",
null));
var rowReference = VisitChild(new TableVariableRowReference() { Id = eachStatement.IterationVariable.Variable, Line = eachStatement.IterationVariable.Line });
loop.Statements.Add(new CodeAssignStatement(rowReference.CodeExpression, new CodePropertyReferenceExpression(new CodeTypeReferenceExpression("x"), "Current")));
var blockArgs = VisitChild(eachStatement.Block, new CodeDomArg() { Tag = true });
loop.Statements.AddRange(blockArgs.ParentStatements);
CallOnProgress(loop.Statements, false);
method.Statements.Add(loop);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_mainType.Type.Members.Add(method);
_codeStack.Peek().ParentStatements.Add(methodcall);
_codeStack.Peek().CodeExpression = methodcall;
}
}
示例8: Clone
public static CodeIterationStatement Clone(this CodeIterationStatement statement)
{
if (statement == null) return null;
CodeIterationStatement s = new CodeIterationStatement();
s.EndDirectives.AddRange(statement.EndDirectives);
s.IncrementStatement = statement.IncrementStatement.Clone();
s.InitStatement = statement.InitStatement.Clone();
s.LinePragma = statement.LinePragma;
s.StartDirectives.AddRange(statement.StartDirectives);
s.Statements.AddRange(statement.Statements.Clone());
s.TestExpression = statement.TestExpression.Clone();
s.UserData.AddRange(statement.UserData);
return s;
}
示例9: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeStatement init = new CodeStatement ();
CodeExpression test = new CodeExpression ();
CodeStatement increment = new CodeStatement ();
CodeStatement[] statements = new CodeStatement[2] { init, increment };
CodeIterationStatement cis = new CodeIterationStatement (init, test, increment, statements);
Assert.AreSame (increment, cis.IncrementStatement, "IncrementStatement");
cis.IncrementStatement = new CodeStatement ();
Assert.AreSame (init, cis.InitStatement, "InitStatement");
cis.InitStatement = new CodeStatement ();
Assert.AreEqual (2, cis.Statements.Count, "Statements");
Assert.AreSame (test, cis.TestExpression, "TestExpression");
cis.TestExpression = new CodeExpression ();
}
示例10: GetKeywordFromCodeDom
public void GetKeywordFromCodeDom()
{
CodeStatement st = new CodeExpressionStatement(new CodeArgumentReferenceExpression("foo"));
CodeExpression exp = new CodeArgumentReferenceExpression("foo");
CodeIterationStatement it = new CodeIterationStatement(st, exp, st);
CodeConditionStatement cond = new CodeConditionStatement(exp);
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
}
示例11: GenerateForLoop
private CodeIterationStatement GenerateForLoop(GroupActivity groupActivity)
{
var coreGroupMethodStatement = new CodeStatementCollection();
// put the current element in the declare variable
// TODO convert the $Variable in variable like in Xpath
CodeVariableDeclarationStatement iterationElementSlotDeclaration = new CodeVariableDeclarationStatement("var", groupActivity.IterationElementSlot, new CodeVariableReferenceExpression(groupActivity.Over + "[" + groupActivity.IndexSlot + "]"));
coreGroupMethodStatement.Add(iterationElementSlotDeclaration);
// get the core loop code
coreGroupMethodStatement.AddRange(this.GenerateCoreGroupMethod(groupActivity));
var array = new CodeStatement[coreGroupMethodStatement.Count];
coreGroupMethodStatement.CopyTo(array, 0);
// put it then in the loop
CodeIterationStatement forLoop = new CodeIterationStatement(new CodeVariableDeclarationStatement(typeof(int), groupActivity.IndexSlot, new CodePrimitiveExpression(0)),
new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(groupActivity.IndexSlot), CodeBinaryOperatorType.LessThan, new CodeVariableReferenceExpression(groupActivity.Over + ".Lenght")),
new CodeAssignStatement(new CodeVariableReferenceExpression(groupActivity.IndexSlot), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(groupActivity.IndexSlot), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1))),
array);
return forLoop;
}
示例12: Visit
public void Visit(ExpandExpression expression)
{
var fromDomArgs = VisitChild(expression.From);
var toDomArgs = VisitChild(expression.To);
var expressionArgs = VisitChild(expression.Expression);
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "Expand_" + fromDomArgs.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
method.ReturnType = new CodeTypeReference("Table", new CodeTypeReference("Expand"));
method.Statements.Add(new CodeVariableDeclarationStatement(method.ReturnType, "expandTable",
new CodeObjectCreateExpression(new CodeTypeReference("RuntimeTable", new CodeTypeReference("Expand")))));
method.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "x"));
var loop = new CodeIterationStatement();
loop.InitStatement = new CodeAssignStatement( new CodeVariableReferenceExpression("x"), fromDomArgs.CodeExpression);
loop.TestExpression = new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("x"),
CodeBinaryOperatorType.LessThanOrEqual, toDomArgs.CodeExpression);
loop.IncrementStatement = new CodeAssignStatement(new CodeVariableReferenceExpression("x"), new CodeBinaryOperatorExpression(
new CodeVariableReferenceExpression("x"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1)));
loop.Statements.Add(new CodeVariableDeclarationStatement("Expand", "expand", new CodeObjectCreateExpression("Expand")));
loop.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("expand"), "value"),
expressionArgs.CodeExpression));
loop.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("expandTable"), "Add",
new CodeVariableReferenceExpression("expand")));
method.Statements.Add(loop);
method.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("expandTable")));
_mainType.Type.Members.Add(method);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_codeStack.Peek().CodeExpression = methodcall;
_codeStack.Peek().Scope = new ScopeData<TableDescriptor> { Type = Expand.Columns, CodeDomReference = method.ReturnType };
}
示例13: EmitIteration
void EmitIteration(CodeIterationStatement iteration)
{
EmitStatement(iteration.InitStatement);
WriteSpace();
writer.Write(Parser.FlowWhile);
writer.Write(Parser.ParenOpen);
depth++;
EmitExpression(iteration.TestExpression);
depth--;
writer.Write(Parser.ParenClose);
WriteSpace();
writer.Write(Parser.BlockOpen);
depth++;
EmitStatements(iteration.Statements);
EmitStatement(iteration.IncrementStatement);
depth--;
WriteSpace();
writer.Write(Parser.BlockClose);
}
示例14: CreateGetLoginsMethod
private void CreateGetLoginsMethod(CodeTypeDeclaration type)
{
CodeMemberMethod method = new CodeMemberMethod();
CodeTypeReference returnType = CreateTaskTypeReference();
returnType.TypeArguments.Add(CodeDomUtilities.GetGenericType(typeof(IList<>), "Microsoft.AspNet.Identity.UserLoginInfo"));
method.ReturnType = returnType;
method.Attributes = MemberAttributes.Public;
method.Name = "GetLoginsAsync";
method.Parameters.Add(new CodeParameterDeclarationExpression(IdentityUser.ClrFullTypeName, "user"));
method.ImplementationTypes.Add(GetGenericInterfaceType("Microsoft.AspNet.Identity.IUserLoginStore", false));
if (CanImplementGenericInterfaces)
{
method.ImplementationTypes.Add(GetGenericInterfaceType("Microsoft.AspNet.Identity.IUserLoginStore", true));
}
method.Statements.Add(CodeDomUtilities.CreateParameterThrowIfNull("user"));
method.Statements.Add(new CodeVariableDeclarationStatement(CodeDomUtilities.GetGenericType(typeof(IList<>), "Microsoft.AspNet.Identity.UserLoginInfo"), "result", new CodeObjectCreateExpression(CodeDomUtilities.GetGenericType(typeof(List<>), "Microsoft.AspNet.Identity.UserLoginInfo"))));
var enumerator = new CodeVariableDeclarationStatement(CodeDomUtilities.GetGenericType(typeof(IEnumerator<>), IdentityUserLogin.ClrFullTypeName), "enumerator");
enumerator.InitExpression = new CodeMethodInvokeExpression(new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("user"), IdentityUser.LoginsProperty.Name), "GetEnumerator");
var iteration = new CodeIterationStatement();
iteration.InitStatement = enumerator;
iteration.TestExpression = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("enumerator"), "MoveNext");
iteration.IncrementStatement = new CodeSnippetStatement("");
iteration.Statements.Add(new CodeVariableDeclarationStatement(IdentityUserLogin.ClrFullTypeName, "userLogin", new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("enumerator"), "Current")));
// V1 & V2: public UserLoginInfo(string loginProvider, string providerKey)
// V3: public UserLoginInfo(string loginProvider, string providerKey, string displayName)
var createExpression = new CodeObjectCreateExpression("Microsoft.AspNet.Identity.UserLoginInfo");
if (IdentityUserLogin.ProviderNameProperty != null)
{
createExpression.Parameters.Add(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userLogin"), IdentityUserLogin.ProviderNameProperty.Name));
}
else
{
createExpression.Parameters.Add(new CodePrimitiveExpression(null));
}
createExpression.Parameters.Add(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userLogin"), IdentityUserLogin.ProviderKeyProperty.Name));
if (IdentityProducer.TargetVersion == AspNetIdentityVersion.Version3)
{
if (IdentityUserLogin.ProviderDisplayNameProperty != null)
{
createExpression.Parameters.Add(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userLogin"), IdentityUserLogin.ProviderDisplayNameProperty.Name));
}
else
{
createExpression.Parameters.Add(new CodePrimitiveExpression(null));
}
}
iteration.Statements.Add(
new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("result"), "Add",
createExpression));
method.Statements.Add(iteration);
method.Statements.Add(CreateTaskResult(new CodeVariableReferenceExpression("result")));
type.Members.Add(method);
}
示例15: CreateGetClaimsMethod
private void CreateGetClaimsMethod(CodeTypeDeclaration type)
{
CodeMemberMethod method = new CodeMemberMethod();
var returnType = CreateTaskTypeReference();
returnType.TypeArguments.Add(CodeDomUtilities.GetGenericType(typeof(IList<>), ClaimFullTypeName));
method.ReturnType = returnType;
method.Attributes = MemberAttributes.Public;
method.Name = "GetClaimsAsync";
method.Parameters.Add(new CodeParameterDeclarationExpression(IdentityUser.ClrFullTypeName, "user"));
method.ImplementationTypes.Add(GetGenericInterfaceType("Microsoft.AspNet.Identity.IUserClaimStore", false));
if (CanImplementGenericInterfaces)
{
method.ImplementationTypes.Add(GetGenericInterfaceType("Microsoft.AspNet.Identity.IUserClaimStore", true));
}
method.Statements.Add(CodeDomUtilities.CreateParameterThrowIfNull("user"));
method.Statements.Add(new CodeVariableDeclarationStatement(CodeDomUtilities.GetGenericType(typeof(IList<>), ClaimFullTypeName), "result", new CodeObjectCreateExpression(CodeDomUtilities.GetGenericType(typeof(List<>), ClaimFullTypeName))));
var enumerator = new CodeVariableDeclarationStatement(CodeDomUtilities.GetGenericType(typeof(IEnumerator<>), IdentityUserClaim.ClrFullTypeName), "enumerator");
enumerator.InitExpression = new CodeMethodInvokeExpression(new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("user"), IdentityUser.ClaimsProperty.Name), "GetEnumerator");
var iteration = new CodeIterationStatement();
iteration.InitStatement = enumerator;
iteration.TestExpression = new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("enumerator"), "MoveNext");
iteration.IncrementStatement = new CodeSnippetStatement("");
iteration.Statements.Add(new CodeVariableDeclarationStatement(IdentityUserClaim.ClrFullTypeName, "userClaim", new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("enumerator"), "Current")));
var createExpression = new CodeObjectCreateExpression(ClaimFullTypeName);
if (IdentityUserClaim.OriginalIssuerProperty != null)
{
createExpression.Parameters.Insert(0, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userClaim"), IdentityUserClaim.OriginalIssuerProperty.Name));
}
if (IdentityUserClaim.IssuerProperty != null)
{
createExpression.Parameters.Insert(0, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userClaim"), IdentityUserClaim.IssuerProperty.Name));
}
else if (createExpression.Parameters.Count > 0)
{
createExpression.Parameters.Insert(0, createExpression.Parameters[0]); // OriginalIssuer
}
if (IdentityUserClaim.ValueTypeProperty != null)
{
createExpression.Parameters.Insert(0, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userClaim"), IdentityUserClaim.ValueTypeProperty.Name));
}
else if (createExpression.Parameters.Count > 0)
{
createExpression.Parameters.Insert(0, new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(ClaimValueTypesFullTypeName), "String"));
}
createExpression.Parameters.Insert(0, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userClaim"), IdentityUserClaim.ValueProperty.Name));
createExpression.Parameters.Insert(0, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("userClaim"), IdentityUserClaim.TypeProperty.Name));
iteration.Statements.Add(
new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("result"), "Add",
createExpression));
method.Statements.Add(iteration);
method.Statements.Add(CreateTaskResult(new CodeVariableReferenceExpression("result")));
type.Members.Add(method);
}