Add() public method

public Add ( System.CodeDom.CodeExpression value ) : int
value System.CodeDom.CodeExpression
return int
        public static CodeStatementCollection BuildDetectChangedMembers(TableViewTableTypeBase table)
        {
            CodeStatementCollection ValidationSetStatement = new CodeStatementCollection();
            String PocoTypeName = "this";
            ValidationSetStatement.Add(new CodeSnippetExpression("Boolean bResult = new Boolean()"));
            ValidationSetStatement.Add(new CodeSnippetExpression("bResult = false"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                CodeConditionStatement csTest1 = new CodeConditionStatement();

                if (mGraph.IsNullable)
                {
                    csTest1.Condition = new CodeSnippetExpression(PocoTypeName + "." + mGraph.PropertyName() + ".HasValue == true");
                    csTest1.TrueStatements.Add(new CodeSnippetExpression("bResult = true"));
                }
                else
                {
                    csTest1.Condition = new CodeSnippetExpression(PocoTypeName + "." + mGraph.PropertyName() + " == null");
                    csTest1.TrueStatements.Add(new CodeSnippetExpression(""));
                    csTest1.FalseStatements.Add(new CodeSnippetExpression("bResult = true"));
                }
            }

            return ValidationSetStatement;
        }
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     CodeExpression expression;
     CodeTypeDeclaration declaration = manager.Context[typeof(CodeTypeDeclaration)] as CodeTypeDeclaration;
     RootContext context = manager.Context[typeof(RootContext)] as RootContext;
     CodeStatementCollection statements = new CodeStatementCollection();
     if ((declaration != null) && (context != null))
     {
         CodeMemberField field = new CodeMemberField(typeof(IContainer), "components") {
             Attributes = MemberAttributes.Private
         };
         declaration.Members.Add(field);
         expression = new CodeFieldReferenceExpression(context.Expression, "components");
     }
     else
     {
         CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IContainer), "components");
         statements.Add(statement);
         expression = new CodeVariableReferenceExpression("components");
     }
     base.SetExpression(manager, value, expression);
     CodeObjectCreateExpression right = new CodeObjectCreateExpression(typeof(Container), new CodeExpression[0]);
     CodeAssignStatement statement2 = new CodeAssignStatement(expression, right);
     statement2.UserData["IContainer"] = "IContainer";
     statements.Add(statement2);
     return statements;
 }
Example #3
0
 public override void ToCodeDom(CodeStatementCollection statements)
 {
     if (this.expression!=null)
         statements.Add(new CodeExpressionStatement(this.expression.ToCodeDom()));
     else
         statements.Add(new CodeStatement());
 }
		public override object Serialize (IDesignerSerializationManager manager, object value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			object serialized = null;
			string name = manager.GetName (value);

			ExpressionContext exprContext = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			if (exprContext != null && exprContext.PresetValue == value) {
				CodeStatementCollection statements = new CodeStatementCollection ();
				bool isComplete = true;

				statements.Add (new CodeCommentStatement (String.Empty));
				statements.Add (new CodeCommentStatement (name));
				statements.Add (new CodeCommentStatement (String.Empty));
				statements.Add (new CodeAssignStatement (GetFieldReference (manager, name), 
														 base.SerializeCreationExpression (manager, value, out isComplete)));
				base.SerializeProperties (manager, statements, value, new Attribute[0]);
				base.SerializeEvents (manager, statements, value);
				serialized = statements;
			} else {
				serialized = base.Serialize (manager, value);
			}

			return serialized;
		}
        public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, System.CodeDom.CodeMemberMethod method, System.CodeDom.CodeStatementCollection statements, bool debug)
        {
            IMathExpression mathExp = MathExp;

            if (mathExp != null)
            {
                CodeExpression ceCondition = null;
                if (Condition != null)
                {
                    ceCondition = Condition.ExportCode(methodToCompile);
                    if (ceCondition != null)
                    {
                        ceCondition = CompilerUtil.ConvertToBool(Condition.DataType, ceCondition);
                    }
                }
                CodeExpression ce = mathExp.ReturnCodeExpression(methodToCompile);
                if (ce != null)
                {
                    if (ceCondition == null)
                    {
                        statements.Add(new CodeMethodReturnStatement(ce));
                    }
                    else
                    {
                        CodeConditionStatement cd = new CodeConditionStatement();
                        cd.Condition = ceCondition;
                        cd.TrueStatements.Add(new CodeMethodReturnStatement(ce));
                        statements.Add(cd);
                    }
                }
            }
        }
Example #6
0
        protected CodeStatementCollection GenerateSetMappedPropertyCode(CodeExpression targetObj, CodeExpression value)
        {
            CodeStatementCollection statements = new CodeStatementCollection();

            CodePropertyReferenceExpression property = new CodePropertyReferenceExpression(targetObj, MappedProperty.Name);

            if (_mappedProperty.PropertyType.IsArray)
            {
                statements.Add(new CodeAssignStatement(
                    new CodeIndexerExpression(property, new CodePrimitiveExpression(_index)), value));
                return statements;
            }

            if (IsCollection(_mappedProperty.PropertyType))
            {
                CodeBinaryOperatorExpression isNull =
                    new CodeBinaryOperatorExpression(property, CodeBinaryOperatorType.ValueEquality, new CodeSnippetExpression("null"));
                CodeAssignStatement create = new CodeAssignStatement(property, new CodeObjectCreateExpression(_mappedProperty.PropertyType));

                statements.Add(new CodeConditionStatement(isNull, create));
                statements.Add(new CodeMethodInvokeExpression(property, "Add", value));
                return statements;
            }

            statements.Add(new CodeAssignStatement(property, value));
            return statements;
        }
Example #7
0
 public void AddCommentStatement(CodeStatementCollection statements, string comment)
 {
     switch (TargetLanguage)
     {
         case GenerationTargetLanguage.CSharp:
             statements.Add(new CodeSnippetStatement("//" + comment));
             break;
         case GenerationTargetLanguage.VB:
             statements.Add(new CodeSnippetStatement("'" + comment));
             break;
     }
 }
 internal static void BuildExpressionSetup(ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements)
 {
     CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(controlBuilder.ControlType, "dataBindingExpressionBuilderTarget");
     methodStatements.Add(statement);
     CodeVariableReferenceExpression left = new CodeVariableReferenceExpression(statement.Name);
     CodeAssignStatement statement2 = new CodeAssignStatement(left, new CodeCastExpression(controlBuilder.ControlType, new CodeArgumentReferenceExpression("sender")));
     statements.Add(statement2);
     Type bindingContainerType = controlBuilder.BindingContainerType;
     CodeVariableDeclarationStatement statement3 = new CodeVariableDeclarationStatement(bindingContainerType, "Container");
     methodStatements.Add(statement3);
     CodeAssignStatement statement4 = new CodeAssignStatement(new CodeVariableReferenceExpression(statement3.Name), new CodeCastExpression(bindingContainerType, new CodePropertyReferenceExpression(left, "BindingContainer")));
     statements.Add(statement4);
 }
		public virtual object Serialize (IDesignerSerializationManager manager, object value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			object serialized = null;
			bool isComplete = false;
			CodeExpression createExpr = base.SerializeCreationExpression (manager, value, out isComplete);
			if (isComplete) {
				serialized = createExpr;
				base.SetExpression (manager, value, createExpr);
			} else {
				ExpressionContext context = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
				if (context != null && context.PresetValue == value) {
					CodeStatementCollection statements = new CodeStatementCollection ();
					statements.Add (new CodeAssignStatement (context.Expression, createExpr));
					base.SerializeProperties (manager, statements, value, new Attribute[0]);
					base.SerializeEvents (manager, statements, value, new Attribute[0]);
				} else {
					CodeExpression expression = base.GetExpression (manager, value);
					if (expression == null) {
						serialized = expression = createExpr;
						base.SetExpression (manager, value, expression);
					}
				}
			}
			return serialized;
		}
Example #10
0
 public override CodeStatementCollection BuildOperation(CodeGenerationContext ctx, ICodeGeneratorNode element, CodeVariableReferenceExpression value)
 {
     CodeStatementCollection statemets = new CodeStatementCollection();
     statemets.Add(new CodeSnippetExpression(
         string.Format("{0} = ({2})((int){0} >> {1})", value.VariableName, Value, GetValueType(element.MappedProperty).FullName)));
     return statemets;
 }
        internal static void BuildEvalExpression(string field, string formatString, string propertyName,
            Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isEncoded, ref bool hasTempObject) {

            // Altogether, this function will create a statement that looks like this:
            // if (this.Page.GetDataItem() != null) {
            //     target.{{propName}} = ({{propType}}) this.Eval(fieldName, formatString);
            // }

            //     this.Eval(fieldName, formatString)
            CodeMethodInvokeExpression evalExpr = new CodeMethodInvokeExpression();
            evalExpr.Method.TargetObject = new CodeThisReferenceExpression();
            evalExpr.Method.MethodName = EvalMethodName;
            evalExpr.Parameters.Add(new CodePrimitiveExpression(field));
            if (!String.IsNullOrEmpty(formatString)) {
                evalExpr.Parameters.Add(new CodePrimitiveExpression(formatString));
            }

            CodeStatementCollection evalStatements = new CodeStatementCollection();
            BuildPropertySetExpression(evalExpr, propertyName, propertyType, controlBuilder, methodStatements, evalStatements, linePragma, isEncoded, ref hasTempObject);

            // if (this.Page.GetDataItem() != null)
            CodeMethodInvokeExpression getDataItemExpr = new CodeMethodInvokeExpression();
            getDataItemExpr.Method.TargetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page");
            getDataItemExpr.Method.MethodName = GetDataItemMethodName;

            CodeConditionStatement ifStmt = new CodeConditionStatement();
            ifStmt.Condition = new CodeBinaryOperatorExpression(getDataItemExpr, 
                                                                CodeBinaryOperatorType.IdentityInequality, 
                                                                new CodePrimitiveExpression(null));
            ifStmt.TrueStatements.AddRange(evalStatements);
            statements.Add(ifStmt);
        }
Example #12
0
		public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, 
						CodeStatementCollection statements)
		{
			if (statements == null)
				throw new ArgumentNullException ("statements");
			if (manager == null)
				throw new ArgumentNullException ("manager");
			if (value == null)
				throw new ArgumentNullException ("value");
			if (descriptor == null)
				throw new ArgumentNullException ("descriptor");

			IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
			if (service != null) {
				EventDescriptor eventDescriptor = (EventDescriptor) descriptor;
				string methodName = (string) service.GetEventProperty (eventDescriptor).GetValue (value);

				if (methodName != null) {
					CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression (new CodeTypeReference (eventDescriptor.EventType),
																							   _thisReference, methodName);
					CodeExpression targetObject = base.SerializeToExpression (manager, value);
					CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression (targetObject, eventDescriptor.Name);
					statements.Add (new CodeAttachEventStatement (eventRef, listener));
				}
			}
		}
		public override void Serialize (IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
		{
			if (statements == null)
				throw new ArgumentNullException ("statements");
			if (manager == null)
				throw new ArgumentNullException ("manager");
			if (value == null)
				throw new ArgumentNullException ("value");
			if (descriptor == null)
				throw new ArgumentNullException ("descriptor");

			IEventBindingService service = manager.GetService (typeof (IEventBindingService)) as IEventBindingService;
			if (service != null) {
				// In the propertygrid the events are represented by PropertyDescriptors and the value is a string
				// which contains the method name to bind to. The propertydescriptors are managed and created by the 
				// IEventBindingService
				// 
				EventDescriptor ev = (EventDescriptor) descriptor;
				string methodName = (string) service.GetEventProperty (ev).GetValue (value);
				CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression (new CodeTypeReference (ev.EventType), _thisReference, methodName);
				CodeExpression targetObject = base.SerializeToExpression (manager, value);
				CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression (targetObject, ev.Name);
				statements.Add (new CodeAttachEventStatement (eventRef, listener));
			}
		}
 public override void ToCodeDom(CodeStatementCollection statements)
 {
     statements.Add(new CodeAssignStatement(
         left.ToCodeDom(),
         right.ToCodeDom()
         ));
 }
		public virtual object Serialize (IDesignerSerializationManager manager, object value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			bool isComplete = true;
			CodeStatementCollection statements = new CodeStatementCollection ();
			ExpressionContext context = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			object serialized = null;

			if (context != null && context.PresetValue == value) {
				string varName = base.GetUniqueName (manager, value);
				CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement (value.GetType (), varName); // declare
				statement.InitExpression = base.SerializeCreationExpression (manager, value, out isComplete); // initialize
				base.SetExpression (manager, value, statement.InitExpression);
				statements.Add (statement);
				serialized = statement;
			} else {
				string name = manager.GetName (value);
				if (name == null)
					name = base.GetUniqueName (manager, value);
				serialized = GetFieldReference (manager, name);
			}

			base.SerializeProperties (manager, statements, value, new Attribute[0]);
			base.SerializeEvents (manager, statements, value, new Attribute[0]);

			return serialized;
		}
 private void BuildControlSkins(CodeStatementCollection statements) {
     foreach (ControlSkinBuilderEntry entry in _controlSkinBuilderEntryList) {
         string skinID = entry.SkinID;
         ControlBuilder builder = entry.Builder;
         statements.Add(BuildControlSkinAssignmentStatement(builder, skinID));
     }
 }
        internal static void BuildExpressionSetup(ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isTwoWayBound, bool designerMode) {
            // {{controlType}} target;
            CodeVariableDeclarationStatement targetDecl = new CodeVariableDeclarationStatement(controlBuilder.ControlType, "dataBindingExpressionBuilderTarget");
            methodStatements.Add(targetDecl);

            CodeVariableReferenceExpression targetExp = new CodeVariableReferenceExpression(targetDecl.Name);

            // target = ({{controlType}}) sender;
            CodeAssignStatement setTarget = new CodeAssignStatement(targetExp,
                                                                    new CodeCastExpression(controlBuilder.ControlType,
                                                                                           new CodeArgumentReferenceExpression("sender")));
            setTarget.LinePragma = linePragma;
            statements.Add(setTarget);

            Type bindingContainerType = controlBuilder.BindingContainerType;
            CodeVariableDeclarationStatement containerDecl = new CodeVariableDeclarationStatement(bindingContainerType, "Container");
            methodStatements.Add(containerDecl);

            // {{containerType}} Container = ({{containerType}}) target.BindingContainer;
            CodeAssignStatement setContainer = new CodeAssignStatement(new CodeVariableReferenceExpression(containerDecl.Name),
                                                                       new CodeCastExpression(bindingContainerType,
                                                                                              new CodePropertyReferenceExpression(targetExp,
                                                                                                                                  "BindingContainer")));
            setContainer.LinePragma = linePragma;
            statements.Add(setContainer);
            string variableName = isTwoWayBound ? "BindItem" : "Item";
            GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, variableName);
            //Generate code for other variable as well at design time in addition to runtime variable for intellisense to work.
            if (designerMode) {
                GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, isTwoWayBound ?  "Item" : "BindItem");
            }
        }
        public void Visit(ProcedureCall call)
        {
            var domArg = new CodeDomArg();

            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Exec_" + domArg.MethodIdentifier;
            method.Attributes = MemberAttributes.Private;
            GenerateCallStatement(method.Statements, call.Line.Line);
            _mainType.Type.Members.Add(method);

            var methodStatements = new CodeStatementCollection();

            var argList = new List<CodeExpression>();
            foreach(var arg in call.Args)
            {
                domArg = VisitChild(arg);
                argList.Add(domArg.CodeExpression);
            }

            methodStatements.Add(
                new CodeVariableDeclarationStatement(call.Name, "r",
                    new CodeObjectCreateExpression(call.Name, argList.ToArray()))
                    );

            methodStatements.Add(
            new CodeAssignStatement(
                new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("r"), "RequestFactory"),
                new CodePropertyReferenceExpression(null, "RequestFactory"))
                );

            var delegateGen = new CodeDelegateCreateExpression(new CodeTypeReference(typeof(Action<ProgressArgs>)),
                new CodeThisReferenceExpression(), "OnProgress");
            methodStatements.Add(new CodeAttachEventStatement(new CodeVariableReferenceExpression("r"), "Progress", delegateGen));

            methodStatements.Add(
                new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("r"), "Run")
            );

            methodStatements.Add(new CodeRemoveEventStatement(new CodeVariableReferenceExpression("r"), "Progress", delegateGen));

            method.Statements.AddRange(methodStatements);

            var methodcall = new CodeMethodInvokeExpression(
              new CodeMethodReferenceExpression(null, method.Name));
            _codeStack.Peek().ParentStatements.Add(methodcall);
        }
 public static CodeStatementCollection Clone(this CodeStatementCollection collection)
 {
     if (collection == null) return null;
     CodeStatementCollection c = new CodeStatementCollection();
     foreach (CodeStatement statement in collection)
         c.Add(statement.Clone());
     return c;
 }
Example #20
0
 public override void ToCodeDom(CodeStatementCollection statements)
 {
     statements.Add(
         new CodeThrowExceptionStatement(
             this.toThrow.ToCodeDom()
             )
         );
 }
 public override void ToCodeDom(CodeStatementCollection statements)
 {
     statements.Add(new CodeConditionStatement(
         this.condition.ToCodeDom(),
         this.trueStatements.ToCodeDomArray(),
         this.falseStatements.ToCodeDomArray()
         ));
 }
 private void AddOutputWriteStatement(CodeStatementCollection methodStatements, CodeExpression expr, CodeLinePragma linePragma)
 {
     CodeStatement outputWriteStatement = this.GetOutputWriteStatement(expr, false);
     if (linePragma != null)
     {
         outputWriteStatement.LinePragma = linePragma;
     }
     methodStatements.Add(outputWriteStatement);
 }
Example #23
0
        public override void ToCodeDom(CodeStatementCollection statements)
        {
            CodeStatementCollection col = new CodeStatementCollection();
            statement.ToCodeDom(col);

            statements.Add(
                new CodeLabeledStatement(label,col[0])
                );
        }
Example #24
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Wrapper.ActionGroup grp, CodeExpression groupVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Action group " + grp.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     ctx.GenerateCreationCode (grp, groupVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
 public CodeStatementCollection DefaultInvocationMethod(Activity activity)
 {
     var activityServiceReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), VariableHelper.ToVariableName(activity.Name));
     var methodInvocation = new CodeMethodInvokeExpression(activityServiceReference, "Execute", new CodeExpression[] { });
     var invocationCodeCollection = new CodeStatementCollection();
     invocationCodeCollection.AddRange(LogActivity(activity));
     invocationCodeCollection.Add(methodInvocation);
     return invocationCodeCollection;
 }
Example #26
0
 public static WidgetMap GenerateCreationCode(CodeNamespace cns, CodeTypeDeclaration type, Gtk.Widget w, CodeExpression widgetVarExp, CodeStatementCollection statements, GenerationOptions options, ArrayList warnings)
 {
     statements.Add (new CodeCommentStatement ("Widget " + w.Name));
     GeneratorContext ctx = new ProjectGeneratorContext (cns, type, statements, options);
     Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (w);
     ctx.GenerateCreationCode (ww, widgetVarExp);
     ctx.EndGeneration ();
     warnings.AddRange (ctx.Warnings);
     return ctx.WidgetMap;
 }
		public override void ToCodeDom(CodeStatementCollection statements)
		{
			statements.Add(
				new CodeTryCatchFinallyStatement(
					this.tryStatements.ToCodeDomArray(),
					this.catchClauses.ToCodeDomArray(),
					this.finallyStatements.ToCodeDomArray()
					)
				);
		}
Example #28
0
 private CodeExpression BuildArray(CodeStatementCollection statements, string name, object value)
 {
     Array array = (Array) value;
     Type type = value.GetType();
     string uniqueVariableName = GetUniqueVariableName(name, statements);
     CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(type.FullName, uniqueVariableName);
     statement.InitExpression = new CodeArrayCreateExpression(type.GetElementType(), array.Length);
     statements.Add(statement);
     CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression(uniqueVariableName);
     string str2 = name + "_";
     for (int i = 0; i < array.Length; i++)
     {
         CodeArrayIndexerExpression left = new CodeArrayIndexerExpression(targetObject, new CodeExpression[0]);
         left.Indices.Add(new CodePrimitiveExpression(i));
         CodeExpression right = this.BuildObject(statements, str2 + i.ToString(), array.GetValue(i));
         statements.Add(new CodeAssignStatement(left, right));
     }
     return targetObject;
 }
Example #29
0
        /// <summary>
        /// Serializes a PaletteGroupView object to the code DOM.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            object            retVal         = value;
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(GroupView), typeof(CodeDomSerializer));

            if (baseSerializer != null)
            {
                retVal = baseSerializer.Serialize(manager, value);
                if (retVal != null)
                {
                    System.CodeDom.CodeStatementCollection stmts = retVal as System.CodeDom.CodeStatementCollection;
                    if (stmts != null)
                    {
                        PaletteGroupView palGrpVw = value as PaletteGroupView;
                        if (palGrpVw != null)
                        {
                            SymbolPalette pal = palGrpVw.Palette;
                            if (pal != null)
                            {
                                // Serialize the palette into the resource file

                                BinaryFormatter        formatter = new BinaryFormatter();
                                System.IO.MemoryStream oStream   = new System.IO.MemoryStream();
                                formatter.Serialize(oStream, pal);
                                string resName = palGrpVw.Name + "." + "Palette";
                                this.SerializeResource(manager, resName, oStream.GetBuffer());
                                oStream.Close();

                                // Add statements to CodeDom to load the palette from
                                // the resource file at run-time

                                string        formClassName = "";
                                IDesignerHost designerHost  = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                                if (designerHost != null)
                                {
                                    formClassName = designerHost.RootComponentClassName;
                                    CodePropertyReferenceExpression exprRefGroupView = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), palGrpVw.Name);
                                    CodeExpression[] loadPalParams = new CodeExpression[]
                                    {
                                        new CodePropertyReferenceExpression(new CodeTypeOfExpression(formClassName), "Assembly"),
                                        new CodePrimitiveExpression(formClassName),
                                        new CodePrimitiveExpression(resName)
                                    };
                                    CodeMethodInvokeExpression stmtLoadPalette = new CodeMethodInvokeExpression(exprRefGroupView, "LoadPalette", loadPalParams);
                                    stmts.Add(stmtLoadPalette);
                                }
                            }
                        }
                    }
                }
            }
            return(retVal);
        }
        public CodeStatementCollection GenerateCodeInvocation( AssignActivity assignActivity)
        {
            var invocationCodeCollection = new CodeStatementCollection();
            invocationCodeCollection.AddRange(DefaultActivityBuilder.LogActivity(assignActivity));

            invocationCodeCollection.AddRange(this.xslBuilder.Build(assignActivity.InputBindings));

            var variableToAssignReference = new CodeFieldReferenceExpression ( new CodeThisReferenceExpression (), VariableHelper.ToVariableName(assignActivity.VariableName));
            var codeInvocation = new CodeAssignStatement (variableToAssignReference, new CodeVariableReferenceExpression(VariableHelper.ToVariableName(assignActivity.VariableName)));
            invocationCodeCollection.Add(codeInvocation);
            return invocationCodeCollection;
        }
		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);
		}
        public CodeStatementCollection GenerateCodeInvocation(GenerateErrorActivity activity)
        {
            var invocationCodeCollection = new CodeStatementCollection();

            // add log
            invocationCodeCollection.AddRange(DefaultActivityBuilder.LogActivity(activity));
            //add the input
            invocationCodeCollection.AddRange(this.xslBuilder.Build(activity.InputBindings));

            // Add the exception Call
            invocationCodeCollection.Add(this.GenerateExceptionStatement(activity));

            return invocationCodeCollection;
        }
Example #33
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            MethodInvokeParameterControl retCtrl = null;
            Dictionary <BaseNodeControl, System.CodeDom.CodeExpression> paramCodeExps = new Dictionary <BaseNodeControl, System.CodeDom.CodeExpression>();

            foreach (var paramNode in mChildNodes)
            {
                if (paramNode is MethodInvokeParameterControl)
                {
                    var pm    = paramNode as MethodInvokeParameterControl;
                    var param = pm.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams;
                    if (param.ParamInfo.ParamName == "Return")
                    {
                        retCtrl = pm;
                        continue;
                    }
                    if (pm.HasLink())
                    {
                        await pm.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, pm.ParamPin, context);

                        var exp = new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParamInfo.ParameterType, pm.GCode_CodeDom_GetValue(pm.ParamPin, context));
                        paramCodeExps[paramNode] = exp;
                        codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                        new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName),
                                                        exp));
                    }
                    else if (mTemplateClassInstance != null)
                    {
                        var    proInfo = mTemplateClassInstance.GetType().GetProperty(param.ParamInfo.ParamName);
                        object proValue;
                        if (proInfo == null)
                        {
                            proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType);
                        }
                        else
                        {
                            proValue = proInfo.GetValue(mTemplateClassInstance);
                        }
                        var valueExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue);
                        paramCodeExps[paramNode] = valueExp;
                        codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName), valueExp));
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            if (retCtrl != null)
            {
                if (retCtrl.HasLink())
                {
                    await retCtrl.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, retCtrl.ParamPin, context);
                }

                System.CodeDom.CodeExpression retExp = null;
                if (retCtrl.HasLink())
                {
                    var retStatement = new System.CodeDom.CodeMethodReturnStatement();
                    retExp = retCtrl.GCode_CodeDom_GetValue(retCtrl.ParamPin, context);
                    paramCodeExps[retCtrl] = retExp;
                }
                else if (mTemplateClassInstance != null)
                {
                    var    param   = retCtrl.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams;
                    var    proInfo = mTemplateClassInstance.GetType().GetProperty("Return");
                    object proValue;
                    if (proInfo == null)
                    {
                        proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType);
                    }
                    else
                    {
                        proValue = proInfo.GetValue(mTemplateClassInstance);
                    }
                    retExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue);
                    paramCodeExps[retCtrl] = retExp;
                }

                #region Debug
                var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                foreach (var paramNode in mChildNodes)
                {
                    if (paramNode is MethodInvokeParameterControl)
                    {
                        var pm = paramNode as MethodInvokeParameterControl;
                        System.CodeDom.CodeExpression exp;
                        if (paramCodeExps.TryGetValue(paramNode, out exp))
                        {
                            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, pm.ParamPin.GetLinkPinKeyName(), exp, pm.GCode_GetTypeString(pm.ParamPin, context), context);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("未实现");
                    }
                }
                var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
                #endregion

                var returnParam = CSParam as ReturnConstructParam;
                foreach (var param in returnParam.MethodInfo.Params)
                {
                    // ref或out,需要将displayType造成的临时变量再赋给原函数参数
                    if ((param.FieldDirection == FieldDirection.Out || param.FieldDirection == FieldDirection.Ref) && param.ParameterDisplayType != null)
                    {
                        codeStatementCollection.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("temp___" + param.ParamName), new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParameterType, new CodeVariableReferenceExpression(param.ParamName))));
                    }
                }
                if (returnParam.MethodInfo.ReturnType.BaseType == typeof(System.Threading.Tasks.Task))
                {
                    var genericType = returnParam.MethodInfo.ReturnType.GetGenericArguments()[0];
                    codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement(new CodeGenerateSystem.CodeDom.CodeCastExpression(genericType, retExp)));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement(new CodeGenerateSystem.CodeDom.CodeCastExpression(returnParam.MethodInfo.ReturnType, retExp)));
                }
            }
            else
            {
                #region Debug
                var debugCodes         = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
                #endregion

                var returnParam = CSParam as ReturnConstructParam;
                foreach (var param in returnParam.MethodInfo.Params)
                {
                    // ref或out,需要将displayType造成的临时变量再赋给原函数参数
                    if ((param.FieldDirection == FieldDirection.Out || param.FieldDirection == FieldDirection.Ref) && param.ParameterDisplayType != null)
                    {
                        codeStatementCollection.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("temp___" + param.ParamName), new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParameterType, new CodeVariableReferenceExpression(param.ParamName))));
                    }
                }
                codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement());
            }
        }