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


C# CodeStatementCollection.CopyTo方法代码示例

本文整理汇总了C#中System.CodeDom.CodeStatementCollection.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# CodeStatementCollection.CopyTo方法的具体用法?C# CodeStatementCollection.CopyTo怎么用?C# CodeStatementCollection.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.CodeDom.CodeStatementCollection的用法示例。


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

示例1: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeStatementCollection coll = new CodeStatementCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (cs), "Add");
			Assert.AreSame (cs, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (cs), "Contains");
			Assert.AreEqual (0, coll.IndexOf (cs), "IndexOf");
			coll.Insert (0, cs);
			coll.Remove (cs);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:CodeStatementCollectionCas.cs

示例2: 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;
        }
开发者ID:swoog,项目名称:EaiConverter,代码行数:20,代码来源:GroupActivityBuilder.cs

示例3: CodeStmtColToArray

 /// <summary>
 /// Codes the STMT col to array.
 /// </summary>
 /// <param name="statmentCollection">The statment collection.</param>
 /// <returns>return CodeStmtColToArray</returns>
 internal static CodeStatement[] CodeStmtColToArray(CodeStatementCollection statmentCollection)
 {
     var tryFinallyStatmanents = new CodeStatement[statmentCollection.Count];
     statmentCollection.CopyTo(tryFinallyStatmanents, 0);
     return tryFinallyStatmanents;
 }
开发者ID:cteiosanu,项目名称:Xsd2Code,代码行数:11,代码来源:CodeDomHelper.cs

示例4: ToCodeDomArray

        public CodeStatement[] ToCodeDomArray()
        {
            CodeStatementCollection col = new CodeStatementCollection();
            ToCodeDom(col);

            CodeStatement[] sts = new CodeStatement[col.Count];
            col.CopyTo(sts,0);

            return sts;
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:10,代码来源:StatementCollection.cs

示例5: BuildNativeWriteObjectMethod

        private CodeMemberMethod BuildNativeWriteObjectMethod(string type, string typeName, CodeNamespace codeNs)
        {
            // Create WriteObject method
            CodeMemberMethod codeMemberMethod = new CodeMemberMethod();
            codeMemberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            codeMemberMethod.ReturnType = new CodeTypeReference(typeof(void));
            codeMemberMethod.Name = "WriteObject";
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("XmlWriter", "writer"));
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "graph"));

            // Add type declaration
            CodeVariableDeclarationStatement declaration = new CodeVariableDeclarationStatement(type, typeName);
            declaration.InitExpression = new CodeCastExpression(type, new CodeVariableReferenceExpression("graph"));
            codeMemberMethod.Statements.Add(declaration);

            // Create temporary member field used to generate write string code
            CodeMemberField memberField = new CodeMemberField(type, typeName);

            // Create conditional write statement
            CodeStatementCollection writeStatements = new CodeStatementCollection();
            if (memberField.Type.ArrayElementType != null && CodeGenUtils.IsNativeClrType(memberField.Type.ArrayElementType.BaseType))
            {
                writeStatements.AddRange(BuildWriteArrayStatements(null, memberField));
            }
            // Else if this is a native type
            else if (Type.GetType(memberField.Type.BaseType) != null)
            {
                writeStatements.Add(BuildWriteStringStatement(null, memberField));
            }
            else
                throw new ArgumentException("Invalid native field type for schema item: " + memberField.Name);

            // Add WriteEndElement statement
            writeStatements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("writer"),
                "WriteEndElement", new CodeExpression[] { }));

            // Convert statement collection to array
            CodeStatement[] writeStatementArray = new CodeStatement[writeStatements.Count];
            writeStatements.CopyTo(writeStatementArray, 0);

            // Build WriteParentElement condition paramters
            CodeVariableReferenceExpression writerParam = new CodeVariableReferenceExpression("writer");
            CodePrimitiveExpression nillableParam = new CodePrimitiveExpression(false);
            CodePrimitiveExpression requiredParam = new CodePrimitiveExpression(true);
            CodeVariableReferenceExpression objectParam = new CodeVariableReferenceExpression("graph");

            // Build WriteParentElement condition statement
            CodeConditionStatement condition = new CodeConditionStatement(new CodeMethodInvokeExpression(null,
                "WriteParentElement",
                new CodeExpression[] { writerParam, nillableParam, requiredParam, objectParam }),
                // True condition code. Build read statements based on contract member type
                writeStatementArray
            );

            // Add condition
            codeMemberMethod.Statements.Add(condition);

            return codeMemberMethod;
        }
开发者ID:prabby,项目名称:miniclr,代码行数:59,代码来源:DCSCodeGen.cs

示例6: BuildNativeReadObjectMethod

        private CodeMemberMethod BuildNativeReadObjectMethod(string type, string typeName)
        {
            // Create ReadObject method
            CodeMemberMethod codeMemberMethod = new CodeMemberMethod();
            codeMemberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            codeMemberMethod.ReturnType = new CodeTypeReference(typeof(object));
            codeMemberMethod.Name = "ReadObject";
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("XmlReader", "reader"));

            // Create temporary variable
            CodeVariableDeclarationStatement varDecl = new CodeVariableDeclarationStatement(type, typeName);
            if (varDecl.Type.ArrayElementType == null)
            {
                if (type == "System.String")
                    varDecl.InitExpression = new CodePrimitiveExpression(null);
            }
            else
                varDecl.InitExpression = new CodeArrayCreateExpression(type, new CodeExpression[] { });
            codeMemberMethod.Statements.Add(varDecl);

            // Create temporary member field used to generate read string code
            CodeMemberField memberField = new CodeMemberField(type, typeName);

            // Create conditional read statement
            CodeStatementCollection readStatements = new CodeStatementCollection();
            if (memberField.Type.ArrayElementType != null && CodeGenUtils.IsNativeClrType(memberField.Type.ArrayElementType.BaseType))
            {
                readStatements.AddRange(BuildReadStringArrayStatements(MemberType.Field, null, memberField));
            }
            // Else if this is a native type
            else if (Type.GetType(memberField.Type.BaseType) != null)
            {
                readStatements.Add(BuildReadStringStatement(MemberType.Field, null, memberField));
            }
            else
                throw new ArgumentException("Invalid native field type for schema item: " + memberField.Name);

            // Add ReadEndElement to condition statements
            readStatements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("reader"),
                "ReadEndElement", new CodeExpression[] { }));

            // Add native type return statement
            readStatements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression(typeName)));

            // Convert statement collection to array
            CodeStatement[] readStatementArray = new CodeStatement[readStatements.Count];
            readStatements.CopyTo(readStatementArray, 0);

            // Build IsParentStartElement if statement
            CodeVariableReferenceExpression readerParam = new CodeVariableReferenceExpression("reader");
            CodePrimitiveExpression nillableParam = new CodePrimitiveExpression(false);
            CodePrimitiveExpression requiredParam = new CodePrimitiveExpression(true);
            CodeConditionStatement condition = new CodeConditionStatement(new CodeMethodInvokeExpression(null,
                "IsParentStartElement",
                new CodeExpression[] { readerParam, nillableParam, requiredParam }),
                readStatementArray);

            // Add condition
            codeMemberMethod.Statements.Add(condition);

            // Add null return statement
            codeMemberMethod.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null)));

            return codeMemberMethod;
        }
开发者ID:prabby,项目名称:miniclr,代码行数:65,代码来源:DCSCodeGen.cs

示例7: BuildMtomReadStringStatements

        private CodeStatementCollection BuildMtomReadStringStatements(MemberType memberType, string classRefName, CodeMemberField memberField)
        {
            CodeStatementCollection statements = new CodeStatementCollection();
            CodeStatementCollection trueStatements = new CodeStatementCollection();
            CodeStatementCollection falseStatements = new CodeStatementCollection();

            // string contentID
            trueStatements.Add(
                new CodeVariableDeclarationStatement(
                    typeof(string),
                    "contentID"
                )
            );
            // contentID = reader.Value;
            trueStatements.Add(
                new CodeAssignStatement(
                    new CodeVariableReferenceExpression("contentID"),
                    new CodeFieldReferenceExpression(
                        new CodeVariableReferenceExpression("reader"),
                        "Value"
                    )
                )
            );
            // reader.MoveToElement();
            trueStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("reader"),
                    "MoveToElement"
                )
            );
            // reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include");
            trueStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("reader"),
                    "ReadStartElement",
                    new CodeExpression[] { 
                            new CodePrimitiveExpression("Include"),
                            new CodePrimitiveExpression("http://www.w3.org/2004/08/xop/include")
                        }
                )
            );
            // reader.ReadEndElement();
            trueStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("reader"),
                    "ReadEndElement"
                )
            );
            // ObjectName.FieldName = GetBodyPartContent(contentID)
            trueStatements.Add(
                new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeVariableReferenceExpression(classRefName),
                        memberField.Name
                    ),
                    new CodeMethodInvokeExpression(
                        null,
                        "GetBodyPartContent",
                        new CodeExpression[] {
                            new CodeVariableReferenceExpression("contentID"),
                            new CodeVariableReferenceExpression("BodyParts")
                        }
                    )
                )
            );

            falseStatements.Add(
                new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeVariableReferenceExpression(classRefName),
                        memberField.Name
                    ),
                    new CodeMethodInvokeExpression(
                        new CodeTypeReferenceExpression("Convert"),
                        "FromBase64String",
                        new CodeExpression[] {
                            new CodeMethodInvokeExpression( 
                                new CodeVariableReferenceExpression("reader"), 
                                "ReadString")
                        }
                    )
                )
            );

            falseStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("reader"),
                    "ReadEndElement"
                )
            );

            CodeStatement[] trues = new CodeStatement[trueStatements.Count];
            CodeStatement[] falses = new CodeStatement[falseStatements.Count];

            trueStatements.CopyTo(trues, 0);
            falseStatements.CopyTo(falses, 0);

            // if( IsAttribute(reader, "href") )
            statements.Add(
                new CodeConditionStatement( 
//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:DCSCodeGen.cs

示例8: GenerateTypeArrayJSONArray

        private CodeMemberMethod GenerateTypeArrayJSONArray()
        {
            var methodDecl = new CodeMemberMethod
            {
                Name = methodName,
                Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static
            };
            methodDecl.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(type.FullName + "[]"), "objs"));
            methodDecl.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("Org.Json.JSONArray"), "jsonArray"));

            var innerStatements = new CodeStatementCollection();
            FillJSONArrayMembers(innerStatements);

            var innerStatementsArray = new CodeStatement[innerStatements.Count];
            innerStatements.CopyTo(innerStatementsArray, 0);

            methodDecl.Statements.Add(
                new CodeIterationStatement(new CodeVariableDeclarationStatement(typeof(int), "i", new CodeSnippetExpression("0")),
                                           new CodeSnippetExpression("i < objs.Length"), new CodeSnippetStatement("i++"),
                                           innerStatementsArray));

            return methodDecl;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:23,代码来源:TypeSerializerBuilder.cs

示例9: GetRequiredLocationsConditionStatements

        static CodeStatement[] GetRequiredLocationsConditionStatements(IList<string> requiredLocations)
        {
            CodeStatementCollection statementCollection = new CodeStatementCollection();
            foreach (string locationName in requiredLocations)
            {
                CodeMethodInvokeExpression invokeValidateExpression = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("returnLocations"), "Add"),
                new CodePrimitiveExpression(locationName));
                statementCollection.Add(invokeValidateExpression);
            }

            CodeStatement[] returnStatements = new CodeStatement[statementCollection.Count];
            statementCollection.CopyTo(returnStatements, 0);

            return returnStatements;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:16,代码来源:TextExpressionCompiler.cs

示例10: GenerateStatementInvocation

        CodeStatement[] GenerateStatementInvocation(CompiledExpressionDescriptor descriptor, bool withLocationReferences, Dictionary<string, int> cacheIndicies)
        {
            string indexString = descriptor.Id.ToString(CultureInfo.InvariantCulture);
            string dataContextVariableName = "valDataContext" + indexString;

            CodeVariableDeclarationStatement dataContextVariable = new CodeVariableDeclarationStatement(
                     new CodeTypeReference(descriptor.TypeName), dataContextVariableName);

            CodeStatementCollection compiledDataContextStatements = new CodeStatementCollection();

            GenerateGetDataContextVariable(descriptor, dataContextVariable, compiledDataContextStatements, withLocationReferences, cacheIndicies);
            compiledDataContextStatements.Add(dataContextVariable);
                        
            CodeMethodInvokeExpression expressionInvoke = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(
                    new CodeVariableReferenceExpression(dataContextVariableName), descriptor.StatementMethodName));
            
            CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(new CodePrimitiveExpression(null));

            compiledDataContextStatements.Add(expressionInvoke);
            compiledDataContextStatements.Add(returnStatement);

            CodeStatement[] returnStatements = new CodeStatement[compiledDataContextStatements.Count];
            compiledDataContextStatements.CopyTo(returnStatements, 0);

            return returnStatements;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:27,代码来源:TextExpressionCompiler.cs

示例11: GenerateReferenceExpressionInvocation

        CodeStatement[] GenerateReferenceExpressionInvocation(CompiledExpressionDescriptor descriptor, bool withLocationReferences, Dictionary<string, int> cacheIndicies)
        {
            string indexString = descriptor.Id.ToString(CultureInfo.InvariantCulture);
            string dataContextVariableName = "refDataContext" + indexString;

            CodeVariableDeclarationStatement dataContextVariable = new CodeVariableDeclarationStatement(
                     new CodeTypeReference(descriptor.TypeName), dataContextVariableName);

            CodeStatementCollection compiledDataContextStatements = new CodeStatementCollection();

            GenerateGetDataContextVariable(descriptor, dataContextVariable, compiledDataContextStatements, withLocationReferences, cacheIndicies);
            compiledDataContextStatements.Add(dataContextVariable);

            CodeExpression getExpression = null;
            CodeExpression setExpression = null;

            if (this.IsVB)
            {
                getExpression = new CodeDelegateCreateExpression(
                        new CodeTypeReference(descriptor.TypeName),
                        new CodeVariableReferenceExpression(dataContextVariableName),
                        descriptor.GetMethodName);
                setExpression = new CodeDelegateCreateExpression(
                        new CodeTypeReference(descriptor.TypeName),
                        new CodeVariableReferenceExpression(dataContextVariableName),
                        descriptor.SetMethodName);
            }
            else
            {
                getExpression = new CodeMethodReferenceExpression(new CodeVariableReferenceExpression(dataContextVariableName), descriptor.GetMethodName);
                setExpression = new CodeMethodReferenceExpression(new CodeVariableReferenceExpression(dataContextVariableName), descriptor.SetMethodName);
            }

            CodeMethodReferenceExpression getLocationMethod = new CodeMethodReferenceExpression(
                new CodeVariableReferenceExpression(dataContextVariableName),
                "GetLocation",
                new CodeTypeReference[] { new CodeTypeReference(descriptor.ResultType) });

            CodeExpression[] getLocationParameters = null;
            if (withLocationReferences)
            {
                getLocationParameters = new CodeExpression[] { 
                    getExpression,  
                    setExpression,
                    new CodeVariableReferenceExpression("expressionId"),
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        rootActivityFieldName),
                    new CodeVariableReferenceExpression("activityContext") };
            }
            else
            {
                getLocationParameters = new CodeExpression[] { 
                    getExpression,  
                    setExpression };
            }

            CodeMethodInvokeExpression getLocationExpression = new CodeMethodInvokeExpression(
                getLocationMethod,
                getLocationParameters);


            CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(getLocationExpression);

            compiledDataContextStatements.Add(returnStatement);
            
            CodeStatement[] returnStatements = new CodeStatement[compiledDataContextStatements.Count];
            compiledDataContextStatements.CopyTo(returnStatements, 0);

            return returnStatements;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:71,代码来源:TextExpressionCompiler.cs

示例12: GenerateTypeArrayJSONArray

        private CodeMemberMethod GenerateTypeArrayJSONArray()
        {
            var methodDecl = new CodeMemberMethod
            {
                Name = methodName + "Array",
                Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static
            };
            methodDecl.ReturnType = new CodeTypeReference(type.FullName + "[]");
            methodDecl.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("Org.Json.JSONArray"), "jsonArray"));

            var innerStatements = new CodeStatementCollection();
            FillJSONArrayMembers(innerStatements);

            var innerStatementsArray = new CodeStatement[innerStatements.Count];
            innerStatements.CopyTo(innerStatementsArray, 0);

            methodDecl.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference("System.Collections.Generic.List<" + type.FullName + ">"), "result", new CodeObjectCreateExpression("System.Collections.Generic.List<" + type.FullName + ">")));

            methodDecl.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "length",
                                                                          new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("jsonArray"), "Length")));

            methodDecl.Statements.Add(
                new CodeIterationStatement(new CodeVariableDeclarationStatement(typeof(int), "i", new CodeSnippetExpression("0")),
                                           new CodeSnippetExpression("i < length"), new CodeSnippetStatement("i++"),
                                           innerStatementsArray));

            methodDecl.Statements.Add(new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodeVariableReferenceExpression("result"), "ToArray")));

            return methodDecl;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:30,代码来源:TypeDeserializerBuilder.cs

示例13: GetPathTraversalStatements

        private IEnumerable<CodeStatement> GetPathTraversalStatements()
        {
            string exp = "";
            IList<AggregateExpressionPathItem> pathItems
                = ExpressionParser.BuildAggregatePathItem(m_contexts[0].Descriptor, m_contexts[0].Member);

            foreach (AggregateExpressionPathItem pathItem in pathItems)
            {
                if (pathItem.IsCollection)
                {
                    exp += string.Format("foreach({0} {1} in {2}.{3})",
                        TypeHelper.GetTypeDefinition(pathItem.Type),
                        pathItem.Object,
                        pathItem.Target,
                        pathItem.Expression);
                }
            }

            exp += Environment.NewLine + "\t\t\t\t{" + Environment.NewLine;
            foreach (AggregateFunctionContext context in m_contexts)
            {
                IEnumerable<string> itemExpressions = context.Generator.GetIterationStatements(context, context.PathItems);
                foreach (string itemExpression in itemExpressions)
                {
                    exp += "\t\t\t\t\t";
                    exp += itemExpression;
                    if(!exp.EndsWith(";"))
                        exp += ";";
                    exp += Environment.NewLine; // todo: smarter way
                }
            }
            exp += "\t\t\t\t}";

            CodeConditionStatement ifStatement = new CodeConditionStatement(
                new CodeSnippetExpression(pathItems[0].Target + "." + pathItems[0].Expression + " != null"),
                new CodeStatement[] { new CodeExpressionStatement(new CodeSnippetExpression(exp)) },
                new CodeStatement[0]);

            CodeStatementCollection statements = new CodeStatementCollection();
            statements.Add(ifStatement);

            CodeStatement[] arr = new CodeStatement[statements.Count];
            statements.CopyTo(arr, 0);
            return arr;
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:45,代码来源:AggregateExpressionBuilder.cs


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