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


C# CodeStatementCollection.Insert方法代码示例

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


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

示例1: Constructor0_Deny_Unrestricted

		public void Constructor0_Deny_Unrestricted ()
		{
			CodeStatementCollection coll = new CodeStatementCollection ();
			Assert.AreEqual (0, coll.Add (cs), "Add");
			Assert.AreSame (cs, coll[0], "this[int]");
			coll.CopyTo (array, 0);
			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: BuildInitStatements

    /*
     * Build first-time intialization statements
     */
    protected override void BuildInitStatements(CodeStatementCollection trueStatements, CodeStatementCollection topLevelStatements) {

        base.BuildInitStatements(trueStatements, topLevelStatements);

        // 



        CodeMemberField fileDependencies = new CodeMemberField(typeof(object), fileDependenciesName);
        fileDependencies.Attributes |= MemberAttributes.Static;
        _sourceDataClass.Members.Add(fileDependencies);

        // Note: it may look like this local variable declaration is redundant. However it is necessary
        // to make this init code re-entrant safe. This way, even if two threads enter the contructor
        // at the same time, they will not add multiple dependencies.

        // e.g. string[] dependencies;
        CodeVariableDeclarationStatement dependencies = new CodeVariableDeclarationStatement();
        dependencies.Type = new CodeTypeReference(typeof(string[]));
        dependencies.Name = dependenciesLocalName;
        // Note: it is important to add all local variables at the top level for CodeDom Subset compliance.
        topLevelStatements.Insert(0, dependencies);

        Debug.Assert(Parser.SourceDependencies != null);

        StringSet virtualDependencies = new StringSet();
        virtualDependencies.AddCollection(Parser.SourceDependencies);

        // e.g. dependencies = new string[{{virtualDependencies.Count}}];;
        CodeAssignStatement assignDependencies = new CodeAssignStatement();
        assignDependencies.Left =
            new CodeVariableReferenceExpression(dependenciesLocalName);
        assignDependencies.Right =
            new CodeArrayCreateExpression(typeof(String), virtualDependencies.Count);
        trueStatements.Add(assignDependencies);

        int i = 0;
        foreach (string virtualDependency in virtualDependencies) {
            // e.g. dependencies[i] = "~/sub/foo.aspx";
            CodeAssignStatement addFileDep = new CodeAssignStatement();
            addFileDep.Left =
                new CodeArrayIndexerExpression(
                    new CodeVariableReferenceExpression(dependenciesLocalName),
                    new CodeExpression[] {new CodePrimitiveExpression(i++)});
            string src = UrlPath.MakeVirtualPathAppRelative(virtualDependency);
            addFileDep.Right = new CodePrimitiveExpression(src);
            trueStatements.Add(addFileDep);
        }

        // e.g. __fileDependencies = this.GetWrappedFileDependencies(dependencies);
        CodeAssignStatement initFile = new CodeAssignStatement();
        initFile.Left = new CodeFieldReferenceExpression(_classTypeExpr, fileDependenciesName);
        CodeMethodInvokeExpression createWrap = new CodeMethodInvokeExpression();
        createWrap.Method.TargetObject = new CodeThisReferenceExpression();
        createWrap.Method.MethodName = "GetWrappedFileDependencies";
        createWrap.Parameters.Add(new CodeVariableReferenceExpression(dependenciesLocalName));
        initFile.Right = createWrap;

#if DBG
        AppendDebugComment(trueStatements);
#endif
        trueStatements.Add(initFile);
    }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:66,代码来源:PageCodeDomTreeGenerator.cs

示例3: GenerateMethod


//.........这里部分代码省略.........
					GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd);
					methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
				}
			}
			
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Assignment of output parameters
			
			CodeStatementCollection outAssign = new CodeStatementCollection ();
			CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults);
			for (int n=0; n<outParams.Length; n++)
			{
				CodeExpression index = new CodePrimitiveExpression (n);
				if (outParams[n] == null)
				{
					CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index));
					outAssign.Add (new CodeMethodReturnStatement (res));
				}
				else
				{
					CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index));
					CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name);
					outAssign.Insert (0, new CodeAssignStatement (var, res));
				}
			}
			
			if (Style == ServiceDescriptionImportStyle.Client) 
			{
				// Invoke call
				
				CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
				CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
				CodeMethodInvokeExpression inv;
				CodeVariableDeclarationStatement dec;
	
				inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams);
				if (outputMembers != null && outputMembers.Count > 0)
				{
					dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
					method.Statements.Add (dec);
					method.Statements.AddRange (outAssign);
				}
				else
					method.Statements.Add (inv);
				
				// Begin Invoke Call
				
				CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
				CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
				inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs);
				methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
				
				// End Invoke call
				
				CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:67,代码来源:SoapProtocolImporter.cs

示例4: CorrectStatements

        private void CorrectStatements(string name, CodeStatementCollection stmts, CodeTypeReference returnType)
        {
            _name = name;
            _referenceCount = 0;
            new CodeDomWalker(stmts).Walk(RenameReturnValue);
            _name = null;

            CodeObjectSource source = Utils.GetTypeReferenceSource(returnType);
            Type type = (source == null ? null : source.Target as Type);
            CodeExpression defaultExpr = (type != null && type.IsPrimitive
                                              ? (CodeExpression) new CodeDefaultValueExpression(returnType)
                                              : new CodePrimitiveExpression(null));
            CodeExpression returnExpr = null;

            if (_referenceCount > 0)
            {
                bool requiresDeclaration = true;
                CodeAssignStatement assignStmt = stmts[stmts.Count - 1] as CodeAssignStatement;

                if (assignStmt != null)
                {
                    CodeVariableReferenceExpression variableStmt = assignStmt.Left as CodeVariableReferenceExpression;

                    if (variableStmt != null && StringUtils.CaseInsensitiveEquals(variableStmt.VariableName, _returnVariableName))
                    {
                        stmts.RemoveAt(stmts.Count - 1);
                        returnExpr = assignStmt.Right;
                        requiresDeclaration = (_referenceCount > 1);
                    }
                }

                if (requiresDeclaration)
                {
                    CodeExpression initExpression = null;
                    assignStmt = stmts[0] as CodeAssignStatement;

                    if (assignStmt != null)
                    {
                        CodeVariableReferenceExpression variableStmt = assignStmt.Left as CodeVariableReferenceExpression;

                        if (variableStmt != null && StringUtils.CaseInsensitiveEquals(variableStmt.VariableName, _returnVariableName))
                        {
                            stmts.RemoveAt(0);
                            initExpression = assignStmt.Right;
                        }
                    }

                    if (initExpression == null)
                    {
                        initExpression = defaultExpr;
                    }

                    stmts.Insert(
                        0,
                        new CodeVariableDeclarationStatement(
                            returnType,
                            _returnVariableName,
                            initExpression));
                }

                if (returnExpr == null)
                {
                    returnExpr = new CodeVariableReferenceExpression(_returnVariableName);
                }
            }
            else
            {
                returnExpr = defaultExpr;
            }

            stmts.Add(new CodeMethodReturnStatement(returnExpr));
        }
开发者ID:Saleslogix,项目名称:SLXMigration,代码行数:72,代码来源:ReturnValueCorrector.cs

示例5: BuildInitStatements

 protected override void BuildInitStatements(CodeStatementCollection trueStatements, CodeStatementCollection topLevelStatements)
 {
     CodeMemberField field;
     base.BuildInitStatements(trueStatements, topLevelStatements);
     field = new CodeMemberField(typeof(object), "__fileDependencies") {
         Attributes = field.Attributes | MemberAttributes.Static
     };
     base._sourceDataClass.Members.Add(field);
     CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement {
         Type = new CodeTypeReference(typeof(string[])),
         Name = "dependencies"
     };
     topLevelStatements.Insert(0, statement);
     StringSet set = new StringSet();
     set.AddCollection(this.Parser.SourceDependencies);
     CodeAssignStatement statement2 = new CodeAssignStatement {
         Left = new CodeVariableReferenceExpression("dependencies"),
         Right = new CodeArrayCreateExpression(typeof(string), set.Count)
     };
     trueStatements.Add(statement2);
     int num = 0;
     foreach (string str in (IEnumerable) set)
     {
         CodeAssignStatement statement3 = new CodeAssignStatement {
             Left = new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("dependencies"), new CodeExpression[] { new CodePrimitiveExpression(num++) })
         };
         string str2 = UrlPath.MakeVirtualPathAppRelative(str);
         statement3.Right = new CodePrimitiveExpression(str2);
         trueStatements.Add(statement3);
     }
     CodeAssignStatement statement4 = new CodeAssignStatement {
         Left = new CodeFieldReferenceExpression(base._classTypeExpr, "__fileDependencies")
     };
     CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
         Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "GetWrappedFileDependencies" }
     };
     expression.Parameters.Add(new CodeVariableReferenceExpression("dependencies"));
     statement4.Right = expression;
     trueStatements.Add(statement4);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:40,代码来源:PageCodeDomTreeGenerator.cs

示例6: HandleResponse

        public virtual void HandleResponse(string idlMethodName, CodeStatementCollection statementsTryRecv, List<CodeStatement> statementsReponse)
        {
            // Create message reader.
            // * Udbus.Core.UdbusMessageReader reader = new Udbus.Core.UdbusMessageReader(msgHandleResp);
            statementsTryRecv.Insert(0, this.CreateMessageReader());

            // * Udbus.Core.NMessageHandle.UdbusMessageHandle msgHandleResp = null;
            statementsReponse.Add(this.DeclareResponseVariable());
            CodeTryCatchFinallyStatement trycatchReceive = this.ReceiveMessage(idlMethodName, statementsTryRecv);
            statementsReponse.Add(trycatchReceive);
        }
开发者ID:jean-edouard,项目名称:win-tools,代码行数:11,代码来源:MarshalBuilderHelper.cs

示例7: BuildLogic

		private static void BuildLogic(CodeStatementCollection statements, ReadOnlyArrayCollection<ParticleSystemLogicStep> steps, bool addMethod)
		{
			Dictionary<string, bool> argsUsed = new Dictionary<string, bool>();
			foreach (string arg in memberTranslate.Keys)
				argsUsed.Add(arg, false);
			argsUsed.Add("rand", false);

			CodeStatementCollection code = new CodeStatementCollection();
			BuildLogic(code, steps, argsUsed, 0);

			//rand requires a local variable
			if (argsUsed["rand"])
				statements.Add(
					new CodeVariableDeclarationStatement(
						typeof(float), "_tmp", new CodePrimitiveExpression(0.0f)));

			for (int i = 0; i < 4; i++)
			{
				if (argsUsed["local" + i])
				{
					code.Insert(0,
						new CodeVariableDeclarationStatement(
							typeof(float), "local"+i, new CodePrimitiveExpression(0.0f)));
				}
			}

			CodeVariableReferenceExpression ref_i = new CodeVariableReferenceExpression("i");

			if (addMethod) // add methods have indices to update...
				ref_i.VariableName = "_i";

			CodeIterationStatement loop = new CodeIterationStatement();
			loop.InitStatement = new CodeVariableDeclarationStatement(typeof(uint), ref_i.VariableName, new CodePrimitiveExpression(0));
			loop.IncrementStatement = new CodeAssignStatement(ref_i,new CodeBinaryOperatorExpression(ref_i, CodeBinaryOperatorType.Add, new CodePrimitiveExpression((uint)1)));
			loop.TestExpression = new CodeBinaryOperatorExpression(ref_i, CodeBinaryOperatorType.LessThan, new CodeArgumentReferenceExpression("count"));

			// uint i = indices[_i];
			if (addMethod)
				loop.Statements.Add(new CodeVariableDeclarationStatement(typeof(uint), "i", new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("indices"), ref_i)));
			else
			{
				//put in velocity logic

				loop.Statements.Add(
					new CodeAssignStatement(Arg("position.x"),
						new CodeBinaryOperatorExpression(Arg("position.x"), CodeBinaryOperatorType.Add,
							new CodeBinaryOperatorExpression(Arg("velocity.x"), CodeBinaryOperatorType.Multiply, Arg("delta_time")))));

				loop.Statements.Add(
					new CodeAssignStatement(Arg("position.y"),
						new CodeBinaryOperatorExpression(Arg("position.y"), CodeBinaryOperatorType.Add,
							new CodeBinaryOperatorExpression(Arg("velocity.y"), CodeBinaryOperatorType.Multiply, Arg("delta_time")))));

				loop.Statements.Add(
					new CodeAssignStatement(Arg("position.z"),
						new CodeBinaryOperatorExpression(Arg("position.z"), CodeBinaryOperatorType.Add,
							new CodeBinaryOperatorExpression(Arg("velocity.z"), CodeBinaryOperatorType.Multiply, Arg("delta_time")))));
			}

			loop.Statements.AddRange(code);

			statements.Add(loop);
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:63,代码来源:CpuParticlesCodeBuilder.cs

示例8: Insert_Null

		public void Insert_Null ()
		{
			CodeStatementCollection coll = new CodeStatementCollection ();
			coll.Insert (0, (CodeStatement) null);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:CodeStatementCollectionTest.cs

示例9: Insert

		public void Insert ()
		{
			CodeStatement cs1 = new CodeStatement ();
			CodeStatement cs2 = new CodeStatement ();

			CodeStatementCollection coll = new CodeStatementCollection ();
			coll.Add (cs1);
			Assert.AreEqual (1, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (cs1), "#2");
			coll.Insert (0, cs2);
			Assert.AreEqual (2, coll.Count, "#3");
			Assert.AreEqual (1, coll.IndexOf (cs1), "#4");
			Assert.AreEqual (0, coll.IndexOf (cs2), "#5");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:CodeStatementCollectionTest.cs

示例10: MakeSignalParameters

        static public void MakeSignalParameters(CodeTypeDeclaration typedeclArgs,
            CodeTypeFactory codetypefactoryOut,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            string methodName,
            string idlSignalName,
            IList<IDLSignalArgument> arguments,
            CodeParameterDeclarationExpressionCollection parameters,
            CodeStatementCollection statements,
            Udbus.Parsing.BuildContext context,
            MarshalBuilderHelper codebuilder)
        {
            CodeStatementCollection statementsTryRecv = new CodeStatementCollection();
            int nOutArgCounter = 0;
            List<CodeMethodInvokeExpression> invokemethodsBuild = new List<CodeMethodInvokeExpression>();
            CodeConditionStatement condOut = null; // Root if statement for out parameters.
            CodeConditionStatement condOutIter = null; // Most nested if statement for out parameters.
            CodeStatementCollection stmtsFinishResult = new CodeStatementCollection();
            CodeTypeReference typerefParamIter = CodeBuilderCommon.typerefUnknownParameters;
            string argNameIter = arguments != null && arguments.Count > 0 ? arguments[0].Name : "UnknownParameters";

            CodeThrowExceptionStatement throwargOutPrev = codebuilder.CreateArgumentOutException(idlSignalName);

            // WAXME
            //CodeConstructor constructorArgs = new CodeConstructor();
            //constructorArgs.Attributes = MemberAttributes.Public;
            foreach (IDLSignalArgument idlSignalArg in arguments)
            {
                argNameIter = idlSignalArg.Name;

                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                //Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod, idlMethodArg);
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLArgumentTypeNameBuilder(idlIntf, methodName);
                ParamCodeTypeHolderMarshalBase paramtypeHolder = null;
                CodeTypeReference typerefParam = null;
                if (condOut == null)
                {
                    codebuilder.PrefixOutParams(ref condOut, ref condOutIter, idlSignalName, ref nOutArgCounter, ref throwargOutPrev);
                }

                // Handle the signal argument in the message.
                CodeConditionStatement condVarResult;
                codebuilder.MakeOutArgument(statements
                    , stmtsFinishResult
                    , idlSignalName
                    , codetypefactoryOut // Yeah I messed up the naming
                    , ref nOutArgCounter
                    , context
                    , ref throwargOutPrev
                    , idlSignalArg
                    , nameBuilder
                    , ref paramtypeHolder
                    , ref typerefParam
                    , out condVarResult
                );

                codebuilder.StoreCondIterator(ref condOut, ref condOutIter, condVarResult);

                // WAXME
                // Add a field to the <signal>Args class.
                //string argFieldName = CodeBuilderCommon.GetSignalArgFieldName(idlSignalArg.Name);
                //CodeFieldReferenceExpression fielrefdRefArgField = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), argFieldName);
                //typedeclArgs.Members.Add(new CodeMemberField(paramtypeHolder.paramtype.CodeType, argFieldName));
                //CodeMemberProperty propArgField = new CodeMemberProperty();
                //propArgField.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                //propArgField.Type = paramtypeHolder.paramtype.CodeType;
                //propArgField.Name = PropertyNameFromFieldName(argFieldName);
                //propArgField.GetStatements.Add(new CodeMethodReturnStatement(fielrefdRefArgField));
                //typedeclArgs.Members.Add(propArgField);
                //constructorArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, argFieldName));
                //// * this.<signal_arg> = <signal_arg>;
                //constructorArgs.Statements.Add(new CodeAssignStatement(fielrefdRefArgField, new CodeArgumentReferenceExpression(argFieldName)));

            } // Ends loop over arguments

            //typedeclArgs.Members.Add(constructorArgs);

            codebuilder.AssignResults(statementsTryRecv, condOut, condOutIter, stmtsFinishResult, throwargOutPrev
                , idlSignalName, ref nOutArgCounter
            );
            List<CodeStatement> statementsReponse = new List<CodeStatement>();

            // Now receive the response.
            // Create message reader.
            // * Udbus.Core.UdbusMessageReader reader = new Udbus.Core.UdbusMessageReader(msgHandleResp);
            statementsTryRecv.Insert(0, codebuilder.CreateMessageReader());
            statementsReponse.AddRange(statementsTryRecv.Cast<CodeStatement>());
            statements.Add(new CodeConditionStatement(exprResultOk, statementsReponse.ToArray()));
        }
开发者ID:rneilturner,项目名称:win-tools,代码行数:89,代码来源:MarshalBuilder.cs


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