상속: CodeStatement
 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;
 }
예제 #2
0
 private CodeAssignStatement AssignValueTo(Expression<Func<IRule, string>> func, string value)
 {
     var name = Name.Of(func);
     var property = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), name);
     var assignment = new CodeAssignStatement(property, _(value));
     return assignment;
 }
예제 #3
0
        public override void DeclareCodeType(IDLInterface idlIntf)
        {
            // Proxy class.
            typeProxy = new CodeTypeDeclaration(name + "Proxy");
            typeProxy.IsClass = true;
            typeProxy.TypeAttributes = TypeAttributes.Public;
            eventsDeclarationHolder = new CodeTypeDeferredNamespaceDeclarationHolderEvents(idlIntf);
            typeProxy.BaseTypes.Add(genInterfaceName);

            // Interface field.
            CodeMemberField memberProxy = new CodeMemberField(genInterfaceName, proxyName);
            memberProxy.Attributes = MemberAttributes.Private;
            typeProxy.Members.Add(memberProxy); // TODO: Going to need a using or a fully qualified name.

            // Constructor.
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;
            // TODO - use the actual interface type rather than a string.
            paramProxy = new CodeParameterDeclarationExpression(genInterfaceName, proxyName);
            constructor.Parameters.Add(paramProxy);
            thisProxyFieldRef = new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), proxyName
            );
            assignProxy = new CodeAssignStatement(thisProxyFieldRef,
                new CodeArgumentReferenceExpression(proxyName));
            constructor.Statements.Add(assignProxy);
            typeProxy.Members.Add(constructor);

            declarationHolder = new CodeTypeIgnoredNamespaceDeclarationHolderParams(idlIntf);
            contextDeclarationHolder = declarationHolder;

            bAddNamespace = false;
        }
 public override void ImportClass() {
     // grab this here so it gets marked "handled" for both client and server
     SoapAddressBinding soapAddress = ImportContext.Port == null ? null : (SoapAddressBinding)ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding));
     if (ImportContext.Style == ServiceDescriptionImportStyle.Client) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);                                
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
         bool soap11 = true;
         if (ImportContext is Soap12ProtocolImporter) {
             soap11 = false;
             // add version code
             CodeTypeReferenceExpression versionEnumTypeReference = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression versionEnumFieldReference = new CodeFieldReferenceExpression(versionEnumTypeReference, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression versionPropertyReference = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement assignVersionStatement = new CodeAssignStatement(versionPropertyReference, versionEnumFieldReference);
             ctor.Statements.Add(assignVersionStatement);
         }
         ServiceDescription serviceDescription = ImportContext.Binding.ServiceDescription;
         string url = (soapAddress != null) ? soapAddress.Location : null;
         string urlKey = serviceDescription.AppSettingUrlKey;
         string baseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, urlKey, baseUrl, soap11 && !ImportContext.IsEncodedBinding);
     }
     else if (ImportContext.Style == ServiceDescriptionImportStyle.Server) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
 public override void ImportClass()
 {
     SoapAddressBinding binding = (base.ImportContext.Port == null) ? null : ((SoapAddressBinding) base.ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding)));
     if (base.ImportContext.Style == ServiceDescriptionImportStyle.Client)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(base.ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
         bool flag = true;
         if (base.ImportContext is Soap12ProtocolImporter)
         {
             flag = false;
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression right = new CodeFieldReferenceExpression(targetObject, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement statement = new CodeAssignStatement(left, right);
             ctor.Statements.Add(statement);
         }
         ServiceDescription serviceDescription = base.ImportContext.Binding.ServiceDescription;
         string url = (binding != null) ? binding.Location : null;
         string appSettingUrlKey = serviceDescription.AppSettingUrlKey;
         string appSettingBaseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, appSettingUrlKey, appSettingBaseUrl, flag && !base.ImportContext.IsEncodedBinding);
     }
     else if (base.ImportContext.Style == ServiceDescriptionImportStyle.Server)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
예제 #6
0
        /// <summary>
        /// Compose additional items of the test TearDown method.
        /// </summary>
        /// <param name="teardownMethod">A reference to the TearDown method of the test.</param>
        /// <param name="testObjectMemberField">The member field of the object under test.</param>
        /// <param name="testObjectName">The name of the object under test.</param>
        /// <param name="testObjectType">Type of the object under test(OuT).</param>
        protected override void ComposeTestTearDownMethod(
            CodeMemberMethod teardownMethod,
            CodeMemberField testObjectMemberField,
            string testObjectName,
            Type testObjectType)
        {
            /*var invokeExpression = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression("Assert"),
                "AreEqual",
                //new CodePrimitiveExpression("expected")
                new CodeFieldReferenceExpression(testObjectMemberField, "bla")
                , new CodeVariableReferenceExpression("actual"));*/
            var fieldRef1 =
                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), testObjectMemberField.Name);

            // var objectCreate1 = new CodeObjectCreateExpression(testObjectName, new CodeExpression[] { });
            var as1 =
                new CodeAssignStatement(fieldRef1, new CodePrimitiveExpression(null));

            // new CodeAssignStatement(fieldRef1, objectCreate1);

            // Creates a statement using a code expression.
            // var expressionStatement = new CodeExpressionStatement(fieldRef1);
            teardownMethod.Statements.Add(as1);
            base.ComposeTestTearDownMethod(teardownMethod, testObjectMemberField, testObjectName, testObjectType);
        }
예제 #7
0
        public void Visit(FileTable table)
        {
            var descriptor = new TableDescriptor(typeof(FileTable<>));
            var fileTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
            fileTable.BaseTypes.Add(new CodeTypeReference("IRowWriter"));
            fileTable.BaseTypes.Add(new CodeTypeReference("IRowReader"));

            //field
            var fileTableCodeDomType = new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable));
            Scope.Current.Type.Type.Members.Add(
                new CodeMemberField(fileTableCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });

            var locationArg = VisitChild(table.Location);

            //constructor
            Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
                new CodeSnippetExpression(table.Variable),
                new CodeObjectCreateExpression(
                    new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable)))));

            BuildIRowWriterImplementation(fileTable, table.Args);
            BuildIRowReaderImplementation(fileTable, table.Args);

            foreach (var arg in table.Args)
            {
                var domArg = VisitChild(arg);
                fileTable.Members.AddRange(domArg.ParentMemberDefinitions);
                descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive= TablePrimitive.FromString(arg.Type)});
            }

            _mainType.Type.Members.Add(fileTable);

            if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));

            Scope.Current.RegisterTable(table.Variable, descriptor, fileTableCodeDomType);

            //Init Code
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Init_" + fileTable.Name;
            method.Attributes = MemberAttributes.Private;

            _mainType.Type.Members.Add(method);
            var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".Location"), locationArg.CodeExpression);
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".FieldTerminator"), new CodePrimitiveExpression(table.FieldTerminator));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".RowTerminator"), new CodePrimitiveExpression(table.RowTerminator));
            method.Statements.Add(assignment);

            method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable), "Load"));

            var methodcall = new CodeMethodInvokeExpression(
               new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }
예제 #8
0
 protected override void GenerateAssignStatement(System.CodeDom.CodeAssignStatement e)
 {
     GenerateExpression(e.Left);
     Output.Write(" := ");
     GenerateExpression(e.Right);
     Output.WriteLine(";");
 }
예제 #9
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;
        }
예제 #10
0
 public static void ExampleDependencyInjectionLogic(CodeMemberMethod buildMethod)
 {
     // Non file based controls are different than file based controls.
       // Non file based controls are instantiated with "new" inside of a method and returned.
       // They are declared in the first statement.
       CodeVariableDeclarationStatement declaration = (CodeVariableDeclarationStatement)buildMethod.Statements[0];
       // Use the type of the declaration to get the type of the control.
       Type type = Type.GetType(declaration.Type.BaseType);
       // Standard reflection to get all of the properties. You could also look for fields.
       PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
       foreach(PropertyInfo property in properties) {
     // See if the property has the specific attribute we care about.
     object[] injectDeps = property.GetCustomAttributes(typeof(InjectDepAttribute), true);
     if(injectDeps.Length == 1) {
       // Create the code dom to perform the injection.
       // In this example, set the property to the literal the attribute was given.
       CodeStatement setProperty = new CodeAssignStatement(
     new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(declaration.Name), property.Name),
     new CodePrimitiveExpression((injectDeps[0] as InjectDepAttribute).Name + " (the builder method this is set in is '" + buildMethod.Name + "')")
       );
       // Add the statement to the list of statements that make up the builder method.
       // The last statement is the return statement that returns the control.
       // So we insert out injection statement(s) right before it.
       buildMethod.Statements.Insert(buildMethod.Statements.Count - 1, setProperty);
     }
       }
 }
        public void Visit(ProcedureDefinition statement)
        {
            var argList = new List<CodeParameterDeclarationExpression>();
            foreach (var arg in statement.Args)
            {
                var variableType = TablePrimitive.FromString(arg.Type).Type;
                var codeParam = new CodeParameterDeclarationExpression(variableType, arg.Variable);
                Scope.Current.RegisterPrimitive(codeParam.Name, variableType, codeParam.Type);
                Scope.Current.Type.Type.Members.Add(new CodeMemberField() { Name = codeParam.Name, Type = codeParam.Type, Attributes = MemberAttributes.Public | MemberAttributes.Final });

                var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + codeParam.Name), new CodeVariableReferenceExpression(codeParam.Name));
                _mainType.Constructor.Statements.Add(assignment);

                argList.Add(codeParam);
            }

            _mainType.Type.Name = statement.Name;
            _mainType.Constructor.Parameters.Clear();
            _mainType.Constructor.BaseConstructorArgs.Clear();
            _mainType.Constructor.Parameters.AddRange(argList.ToArray());
            _mainType.Constructor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(new CodeTypeReference(typeof(string[])), 0));

            //visit block
            var blockArgs = VisitChild(statement.Block);
            _codeStack.Peek().ParentStatements.AddRange(blockArgs.ParentStatements);
        }
예제 #12
0
		public void CodeAssignStatementTest ()
		{
			CodeSnippetExpression cse1 = new CodeSnippetExpression("A");
			CodeSnippetExpression cse2 = new CodeSnippetExpression("B");

			CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2);
			statement = assignStatement;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"A = B;{0}", NewLine), Generate (), "#1");

			assignStatement.Left = null;
			try {
				Generate ();
				Assert.Fail ("#2");
			} catch (ArgumentNullException) {
			}

			assignStatement.Left = cse1;
			Generate ();

			assignStatement.Right = null;
			try {
				Generate ();
				Assert.Fail ("#3");
			} catch (ArgumentNullException) {
			}

			assignStatement.Right = cse2;
			Generate ();
		}
예제 #13
0
 private void GenerateDefaultConstructor(CodeTypeDeclaration classObject, JsonObject jsonObject)
 {
     CodeConstructor constructor = new CodeConstructor();
     classObject.Members.Add(constructor);
     constructor.Attributes = MemberAttributes.Public;
     CodeAssignStatement statement = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeObjectCreateExpression(jsonObject.GetType(), new CodeExpression[0]));
     constructor.Statements.Add(statement);
 }
 protected override void GenerateAssignStatement(CodeAssignStatement e)
 {
     Output.Write("[CodeAssignStatement: Left=");
     base.GenerateExpression(e.Left);
     Output.Write(", Right=");
     base.GenerateExpression(e.Right);
     Output.WriteLine("]");
 }
예제 #15
0
		public void Constructor0_Deny_Unrestricted ()
		{
			CodeAssignStatement cas = new CodeAssignStatement ();
			Assert.IsNull (cas.Left, "Left");
			cas.Left = new CodeExpression ();
			Assert.IsNull (cas.Right, "Right");
			cas.Right = new CodeExpression ();
		}
 public TypescriptAssignStatement(
     IExpressionFactory expressionFactory,
     CodeAssignStatement codeAssignStatement,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _codeAssignStatement = codeAssignStatement;
     _options = options;
 }
예제 #17
0
 void EmitAssignment(CodeAssignStatement assign)
 {
     EmitExpression(assign.Left);
     writer.Write(Parser.SingleSpace);
     writer.Write(Parser.AssignPre);
     writer.Write(Parser.Equal);
     writer.Write(Parser.SingleSpace);
     EmitExpression(assign.Right);
 }
예제 #18
0
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression left = new CodeExpression ();
			CodeExpression right = new CodeExpression ();
			CodeAssignStatement cas = new CodeAssignStatement (left, right);
			Assert.AreSame (left, cas.Left, "Left");
			cas.Left = new CodeExpression ();
			Assert.AreSame (right, cas.Right, "Right");
			cas.Right = new CodeExpression ();
		}
		protected virtual CodeStatement AddPropertyToPropertyBag(string property)
		{
			CodeStatement assign = new CodeAssignStatement(
				new CodeIndexerExpression(
					new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "PropertyBag"),
					new CodePrimitiveExpression(property)
					),
				new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), property)
				);
			return assign;
		}
예제 #20
0
 void EmitAssignStatement(CodeAssignStatement Assign, bool ForceTypes)
 {
     Depth++;
     Debug("Emitting assignment statement");
     Type Top = EmitAssignment(Assign.Left, Assign.Right, ForceTypes);
     
     if(Top != typeof(void))
         Generator.Emit(OpCodes.Pop);
     
     Depth--;
 }
예제 #21
0
        public void Visit(MsSqlTable table)
        {
            var descriptor = new TableDescriptor(typeof(MsSqlTable<>));
            var sqlTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
            sqlTable.BaseTypes.Add(new CodeTypeReference("IRow"));

            var sqlTableCodeDomType = new CodeTypeReference("MsSqlTable", new CodeTypeReference(table.Variable));
            Scope.Current.Type.Type.Members.Add(
                new CodeMemberField(sqlTableCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });

            Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
               new CodeSnippetExpression(table.Variable),
               new CodeObjectCreateExpression(
                   new CodeTypeReference("MsSqlTable", new CodeTypeReference(table.Variable)))));

            var codeExpressions = new List<CodeExpression>();
            foreach (var arg in table.Args)
            {
                var domArg = VisitChild(arg);
                sqlTable.Members.AddRange(domArg.ParentMemberDefinitions);
                codeExpressions.Add(new CodePrimitiveExpression(arg.Variable));
                descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive = TablePrimitive.FromString(arg.Type) });
            }

            _mainType.Type.Members.Add(sqlTable);

            if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));

            Scope.Current.RegisterTable(table.Variable, descriptor, sqlTableCodeDomType);

            //Init Code
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Init_" + sqlTable.Name;
            method.Attributes = MemberAttributes.Private;

            _mainType.Type.Members.Add(method);

            var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".ConnectionString"), new CodePrimitiveExpression(table.ConnectionString));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".Table"), new CodePrimitiveExpression(table.Table));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".FieldNames"),
                new CodeArrayCreateExpression(new CodeTypeReference(typeof(string)), codeExpressions.ToArray()));
            method.Statements.Add(assignment);

            var methodcall = new CodeMethodInvokeExpression(
               new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }
 public static CodeAssignStatement Clone(this CodeAssignStatement statement)
 {
     if (statement == null) return null;
     CodeAssignStatement s = new CodeAssignStatement();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.Left = statement.Left.Clone();
     s.LinePragma = statement.LinePragma;
     s.Right = statement.Right.Clone();
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.UserData.AddRange(statement.UserData);
     return s;
 }
        private static CodeAssignStatement getAssignDetailStatement(RecordStep step, string dataClass)
        {
            CodeAssignStatement asStatement = new CodeAssignStatement();

            asStatement.Left = new CodePropertyReferenceExpression(step.CompInfo.FindMethod, step.ActionName);

            if (dataClass == null)
                asStatement.Right = new CodePrimitiveExpression(step.ActionParams[0].Value);
            else
                asStatement.Right = step.ActionParams[0].GetVariableReference(dataClass);
            return asStatement;
        }
예제 #24
0
        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;
        }
 internal static void GenerateConstructorStatements(CodeConstructor ctor, string url, string appSettingUrlKey, string appSettingBaseUrl, bool soap11)
 {
     bool flag = (url != null) && (url.Length > 0);
     bool flag2 = (appSettingUrlKey != null) && (appSettingUrlKey.Length > 0);
     CodeAssignStatement statement = null;
     if (flag || flag2)
     {
         CodeExpression expression;
         CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url");
         if (flag)
         {
             expression = new CodePrimitiveExpression(url);
             statement = new CodeAssignStatement(left, expression);
         }
         if (flag && !flag2)
         {
             ctor.Statements.Add(statement);
         }
         else if (flag2)
         {
             CodeVariableReferenceExpression expression3 = new CodeVariableReferenceExpression("urlSetting");
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(ConfigurationManager));
             CodePropertyReferenceExpression expression5 = new CodePropertyReferenceExpression(targetObject, "AppSettings");
             expression = new CodeIndexerExpression(expression5, new CodeExpression[] { new CodePrimitiveExpression(appSettingUrlKey) });
             ctor.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "urlSetting", expression));
             if ((appSettingBaseUrl == null) || (appSettingBaseUrl.Length == 0))
             {
                 expression = expression3;
             }
             else
             {
                 if ((url == null) || (url.Length == 0))
                 {
                     throw new ArgumentException(Res.GetString("IfAppSettingBaseUrlArgumentIsSpecifiedThen0"));
                 }
                 string str = new Uri(appSettingBaseUrl).MakeRelative(new Uri(url));
                 CodeExpression[] parameters = new CodeExpression[] { expression3, new CodePrimitiveExpression(str) };
                 expression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "Concat", parameters);
             }
             CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, expression) };
             CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(expression3, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
             if (flag)
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[] { statement }));
             }
             else
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements));
             }
         }
     }
 }
 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);
 }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConstructorAssignment"/> class.
        /// </summary>
        /// <param name="parameterName">Name of the parameter.</param>
        /// <param name="assignStatement">The assign statement for the parameter.</param>
        /// <param name="memberField">The related member field of the parameter.</param>
        /// <param name="type">The type of the field.</param>
        public ConstructorAssignment(
            string parameterName, CodeAssignStatement assignStatement, CodeMemberField memberField, Type type)
        {
            Guard.NotNullOrEmpty(() => parameterName, parameterName);
            Guard.NotNull(() => assignStatement, assignStatement);
            Guard.NotNull(() => memberField, memberField);
            Guard.NotNull(() => type, type);

            this.ParameterName = parameterName;
            this.AssignStatement = assignStatement;
            this.memberField = memberField;
            this.MemberType = type;
        }
예제 #28
0
 private void GenerateConstructorWithTextParameter(CodeTypeDeclaration classObject, JsonObject jsonObject)
 {
     CodeConstructor constructor = new CodeConstructor();
     classObject.Members.Add(constructor);
     constructor.Attributes = MemberAttributes.Public;
     constructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "text"));
     CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(JsonTextParser), "parser", new CodeObjectCreateExpression(new CodeTypeReference(typeof(JsonTextParser)), new CodeExpression[0]));
     constructor.Statements.Add(statement);
     CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("parser"), "Parse"), new CodeExpression[] { new CodeVariableReferenceExpression("text") });
     CodeAssignStatement statement2 = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeCastExpression(new CodeTypeReference(jsonObject.GetType()), expression));
     constructor.Statements.Add(statement2);
     constructor.Statements.Add(new CodeMethodReturnStatement());
 }
예제 #29
0
        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;
            }
        }
 protected override void Constructor(CodeTypeDeclaration typeProxy, CodeTypeReference typerefDbusInterface)
 {
     CodeConstructor constructor = new CodeConstructor();
     constructor.Attributes = MemberAttributes.Public;
     CodeParameterDeclarationExpression paramProxy = new CodeParameterDeclarationExpression(typerefDbusInterface, CodeBuilderCommon.targetName);
     constructor.Parameters.Add(paramProxy);
     CodeFieldReferenceExpression thisProxyFieldRef = new CodeFieldReferenceExpression(
         new CodeThisReferenceExpression(), CodeBuilderCommon.targetName
     );
     CodeAssignStatement assignProxy = new CodeAssignStatement(thisProxyFieldRef,
         new CodeArgumentReferenceExpression(CodeBuilderCommon.targetName));
     constructor.Statements.Add(assignProxy);
     typeProxy.Members.Add(constructor);
 }
        protected override void ParseElement(XElement element)
        {
            if (!m_firstElement)
                throw new InvalidOperationException();

            var objectParser = new ObjectParser(State);
            objectParser.Parse(element);

            var left = new CodePropertyReferenceExpression(
                new CodeVariableReferenceExpression(Parent.VariableName), Name);
            var right = new CodeVariableReferenceExpression(objectParser.VariableName);
            var assignment = new CodeAssignStatement(left, right);
            State.AddStatement(assignment);
        }
예제 #32
0
        //System.CodeDom.CodeVariableDeclarationStatement mVecVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement();
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            var strValueName = GCode_GetValueName(null, context);

            if (!context.Method.Statements.Contains(mVarDec))
            {
                mVarDec = new CodeAssignStatement(new CodeSnippetExpression(mValueType.FullName + " " + strValueName), CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(mValueType));//, paramCodeName, CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(ParamType));
                context.Method.Statements.Insert(0, mVarDec);
            }
            if (mCtrlvalue_VectorIn.HasLink)
            {
                if (!mCtrlvalue_VectorIn.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlvalue_VectorIn.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlvalue_VectorIn.GetLinkedPinControl(0, true), context);
                }


                if (!codeStatementCollection.Contains(mAssignCode))
                {
                    mAssignCode = new CodeAssignStatement(new System.CodeDom.CodeVariableReferenceExpression(strValueName), mCtrlvalue_VectorIn.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlvalue_VectorIn.GetLinkedPinControl(0, true), context));
                    codeStatementCollection.Add(mAssignCode);
                }
            }
            else
            {
                if (!codeStatementCollection.Contains(mAssignCode))
                {
                    mAssignCode      = new CodeAssignStatement();
                    mAssignCode.Left = new System.CodeDom.CodeVariableReferenceExpression(strValueName);
                    var paramExp = new System.CodeDom.CodeExpression[mLinkInDic.Count];
                    var param    = CSParam as AixConstructionParams;
                    if (param != null)
                    {
                        for (int i = 0; i < mLinkInDic.Count; i++)
                        {
                            paramExp[i] = new System.CodeDom.CodePrimitiveExpression(param.Value[i]);
                        }
                    }
                    mAssignCode.Right = new CodeObjectCreateExpression(mValueType, paramExp);
                    codeStatementCollection.Add(mAssignCode);
                }
            }

            foreach (var data in mLinkInDic)
            {
                var linkOI = data.Element;
                if (linkOI.HasLink)
                {
                    if (!linkOI.GetLinkedObject(0, true).IsOnlyReturnValue)
                    {
                        await linkOI.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkOI.GetLinkedPinControl(0, true), context);
                    }

                    var fieldRef = new System.CodeDom.CodeFieldReferenceExpression();
                    fieldRef.TargetObject = new CodeVariableReferenceExpression(strValueName);
                    fieldRef.FieldName    = data.KeyName;
                    var statValAss = new System.CodeDom.CodeAssignStatement();
                    statValAss.Left  = fieldRef;
                    statValAss.Right = new CodeGenerateSystem.CodeDom.CodeCastExpression(typeof(float), linkOI.GetLinkedObject(0, true).GCode_CodeDom_GetValue(linkOI.GetLinkedPinControl(0, true), context));
                    codeStatementCollection.Add(statValAss);
                }
            }
        }
예제 #33
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            var strValueName = GCode_GetValueName(null, context);

            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                mVariableDeclaration.Type           = new CodeTypeReference(mValueType);
                mVariableDeclaration.Name           = strValueName;
                mVariableDeclaration.InitExpression = new CodeObjectCreateExpression(mValueType, new CodePrimitiveExpression(ColorBrush.Color.A / 255.0f),
                                                                                     new CodePrimitiveExpression(ColorBrush.Color.R / 255.0f),
                                                                                     new CodePrimitiveExpression(ColorBrush.Color.G / 255.0f),
                                                                                     new CodePrimitiveExpression(ColorBrush.Color.B / 255.0f));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            if (mCtrlvalue_ColorIn.HasLink)
            {
                if (!mCtrlvalue_ColorIn.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlvalue_ColorIn.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, element, context);
                }

                var assignStatement = new System.CodeDom.CodeAssignStatement(
                    new System.CodeDom.CodeVariableReferenceExpression(strValueName),
                    mCtrlvalue_ColorIn.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlvalue_ColorIn.GetLinkedPinControl(0, true), context));
                codeStatementCollection.Add(assignStatement);
            }

            // r、g、b、a有链接的情况
            foreach (var link in mInComponentLinks)
            {
                if (link.HasLink)
                {
                    if (!link.GetLinkedObject(0, true).IsOnlyReturnValue)
                    {
                        await link.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, element, context);
                    }

                    var fieldRef = new CodeFieldReferenceExpression();
                    fieldRef.TargetObject = new CodeVariableReferenceExpression(strValueName);
                    fieldRef.FieldName    = GetValuePureName(link);
                    var statValAss = new CodeAssignStatement();
                    statValAss.Left  = fieldRef;
                    statValAss.Right = new CodeGenerateSystem.CodeDom.CodeCastExpression(typeof(float), link.GetLinkedObject(0, true).GCode_CodeDom_GetValue(link.GetLinkedPinControl(0, true), context));
                    codeStatementCollection.Add(statValAss);
                }
            }

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlvalue_ColorOut.GetLinkPinKeyName(),
                                                                   new CodeVariableReferenceExpression(GCode_GetValueName(mCtrlvalue_ColorOut, context)),
                                                                   GCode_GetTypeString(mCtrlvalue_ColorOut, context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutR.GetLinkPinKeyName(),
                                                                   new CodeVariableReferenceExpression(GCode_GetValueName(mCtrlValueOutR, context)),
                                                                   GCode_GetTypeString(mCtrlValueOutR, context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutG.GetLinkPinKeyName(),
                                                                   new CodeVariableReferenceExpression(GCode_GetValueName(mCtrlValueOutG, context)),
                                                                   GCode_GetTypeString(mCtrlValueOutG, context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutB.GetLinkPinKeyName(),
                                                                   new CodeVariableReferenceExpression(GCode_GetValueName(mCtrlValueOutB, context)),
                                                                   GCode_GetTypeString(mCtrlValueOutB, context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutA.GetLinkPinKeyName(),
                                                                   new CodeVariableReferenceExpression(GCode_GetValueName(mCtrlValueOutA, context)),
                                                                   GCode_GetTypeString(mCtrlValueOutA, context), context);
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
        }
예제 #34
0
        // Create a CodeDOM graph.
        static void CreateGraph(CodeCompileUnit cu)
        {
            cu.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start,
                                                           "Compile Unit Region"));
            cu.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End,
                                                         string.Empty));
            CodeChecksumPragma pragma1 = new CodeChecksumPragma();

            pragma1.FileName            = "c:\\temp\\test\\OuterLinePragma.txt";
            pragma1.ChecksumAlgorithmId = HashMD5;
            pragma1.ChecksumData        = new byte[] { 0xAA, 0xAA };
            cu.StartDirectives.Add(pragma1);
            CodeChecksumPragma pragma2 = new CodeChecksumPragma("test.txt", HashSHA1, new byte[] { 0xBB, 0xBB, 0xBB });

            cu.StartDirectives.Add(pragma2);

            CodeNamespace ns = new CodeNamespace("Namespace1");

            ns.Imports.Add(new CodeNamespaceImport("System"));
            ns.Imports.Add(new CodeNamespaceImport("System.IO"));
            cu.Namespaces.Add(ns);
            ns.Comments.Add(new CodeCommentStatement("Namespace Comment"));
            CodeTypeDeclaration cd = new CodeTypeDeclaration("Class1");

            ns.Types.Add(cd);

            cd.Comments.Add(new CodeCommentStatement("Outer Type Comment"));
            cd.LinePragma = new CodeLinePragma("c:\\temp\\test\\OuterLinePragma.txt", 300);

            CodeMemberMethod method1 = new CodeMemberMethod();

            method1.Name       = "Method1";
            method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;


            CodeMemberMethod method2 = new CodeMemberMethod();

            method2.Name       = "Method2";
            method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            method2.Comments.Add(new CodeCommentStatement("Method 2 Comment"));

            cd.Members.Add(method1);
            cd.Members.Add(method2);

            cd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start,
                                                           "Outer Type Region"));

            cd.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End,
                                                         string.Empty));

            CodeMemberField field1 = new CodeMemberField(typeof(String), "field1");

            cd.Members.Add(field1);
            field1.Comments.Add(new CodeCommentStatement("Field 1 Comment"));

            CodeRegionDirective codeRegionDirective1 = new CodeRegionDirective(CodeRegionMode.Start,
                                                                               "Field Region");

            field1.StartDirectives.Add(codeRegionDirective1);
            CodeRegionDirective codeRegionDirective2 = new CodeRegionDirective(CodeRegionMode.End,
                                                                               "");

            codeRegionDirective2.RegionMode = CodeRegionMode.End;
            codeRegionDirective2.RegionText = string.Empty;
            field1.EndDirectives.Add(codeRegionDirective2);

            CodeSnippetStatement snippet1 = new CodeSnippetStatement();

            snippet1.Value = "            Console.WriteLine(field1);";

            CodeRegionDirective regionStart = new CodeRegionDirective(CodeRegionMode.End, "");

            regionStart.RegionText = "Snippet Region";
            regionStart.RegionMode = CodeRegionMode.Start;
            snippet1.StartDirectives.Add(regionStart);
            snippet1.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            // CodeStatement example
            CodeConstructor constructor1 = new CodeConstructor();

            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeStatement codeAssignStatement1 = new CodeAssignStatement(
                new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(),
                    "field1"),
                new CodePrimitiveExpression("value1"));

            codeAssignStatement1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Statements Region"));
            cd.Members.Add(constructor1);
            codeAssignStatement1.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
            method2.Statements.Add(codeAssignStatement1);
            method2.Statements.Add(snippet1);
        }