private void AddTransactionMembers(CodeTypeDeclaration dataComponentClass)
        {
            Type transactionType = this.designTable.PropertyCache.TransactionType;

            if (transactionType != null)
            {
                CodeTypeReference type = CodeGenHelper.GlobalType(transactionType);
                dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(type, DataComponentNameHandler.TransactionVariableName));
                CodeMemberProperty property = CodeGenHelper.PropertyDecl(type, DataComponentNameHandler.TransactionPropertyName, MemberAttributes.Assembly | MemberAttributes.Final);
                property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName)));
                property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName), CodeGenHelper.Argument("value")));
                CodeStatement  initStmt       = CodeGenHelper.VariableDecl(CodeGenHelper.Type(typeof(int)), "i", CodeGenHelper.Primitive(0));
                CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), "Length"));
                CodeStatement  incrementStmt  = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1)));
                CodeExpression transaction    = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i")), "Transaction");
                CodeExpression oldTransaction = CodeGenHelper.Variable("oldTransaction");
                CodeExpression newTransaction = CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName);
                CodeStatement  statement3     = this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction);
                property.SetStatements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 }));
                CodeExpression exp         = CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName);
                CodeExpression expression6 = CodeGenHelper.Property(exp, "DeleteCommand");
                transaction = CodeGenHelper.Property(expression6, "Transaction");
                property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction)));
                expression6 = CodeGenHelper.Property(exp, "InsertCommand");
                transaction = CodeGenHelper.Property(expression6, "Transaction");
                property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction)));
                expression6 = CodeGenHelper.Property(exp, "UpdateCommand");
                transaction = CodeGenHelper.Property(expression6, "Transaction");
                property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction)));
                dataComponentClass.Members.Add(property);
            }
        }
コード例 #2
0
        private CodeTypeDeclaration CreateTypedRowEventArg(DesignTable designTable)
        {
            if (designTable == null)
            {
                throw new InternalException("DesignTable should not be null.");
            }
            DataTable           dataTable               = designTable.DataTable;
            string              generatorRowClassName   = designTable.GeneratorRowClassName;
            string              generatorTableClassName = designTable.GeneratorTableClassName;
            string              type        = designTable.GeneratorRowClassName;
            CodeTypeDeclaration declaration = CodeGenHelper.Class(designTable.GeneratorRowEvArgName, false, TypeAttributes.Public);

            declaration.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(EventArgs)));
            declaration.Comments.Add(CodeGenHelper.Comment("Row event argument class", true));
            declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.Type(type), "eventRow"));
            declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "eventAction"));
            declaration.Members.Add(this.EventArgConstructor(type));
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(type), "Row", MemberAttributes.Public | MemberAttributes.Final);

            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventRow")));
            declaration.Members.Add(property);
            property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "Action", MemberAttributes.Public | MemberAttributes.Final);
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventAction")));
            declaration.Members.Add(property);
            return(declaration);
        }
コード例 #3
0
        private CodeConstructor RowConstructor(string tableClassName, string tableFieldName)
        {
            CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Assembly | MemberAttributes.Final);

            constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(DataRowBuilder)), "rb"));
            constructor.BaseConstructorArgs.Add(CodeGenHelper.Argument("rb"));
            constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), tableFieldName), CodeGenHelper.Cast(CodeGenHelper.Type(tableClassName), CodeGenHelper.Property(CodeGenHelper.This(), "Table"))));
            return(constructor);
        }
        private void AddClearBeforeFillMembers(CodeTypeDeclaration dataComponentClass)
        {
            dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(bool)), DataComponentNameHandler.ClearBeforeFillVariableName));
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(bool)), DataComponentNameHandler.ClearBeforeFillPropertyName, MemberAttributes.Public | MemberAttributes.Final);

            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.ClearBeforeFillVariableName)));
            property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.ClearBeforeFillVariableName), CodeGenHelper.Argument("value")));
            dataComponentClass.Members.Add(property);
        }
コード例 #5
0
        private CodeConstructor EventArgConstructor(string rowConcreteClassName)
        {
            CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Public | MemberAttributes.Final);

            constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(rowConcreteClassName), "row"));
            constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "action"));
            constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), "eventRow"), CodeGenHelper.Argument("row")));
            constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), "eventAction"), CodeGenHelper.Argument("action")));
            return(constructor);
        }
コード例 #6
0
 internal void AddTableColumnProperties(CodeTypeDeclaration dataTableClass)
 {
     if (this.columns != null)
     {
         foreach (DesignColumn column in this.columns)
         {
             CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataColumn)), column.GeneratorColumnPropNameInTable, MemberAttributes.Public | MemberAttributes.Final);
             property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), column.GeneratorColumnVarNameInTable)));
             dataTableClass.Members.Add(property);
         }
     }
 }
コード例 #7
0
        private void AddSchemaSerializationModeMembers(CodeTypeDeclaration dataSourceClass)
        {
            CodeMemberField field = CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(SchemaSerializationMode)), "_schemaSerializationMode", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), this.dataSource.SchemaSerializationMode.ToString()));

            dataSourceClass.Members.Add(field);
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(SchemaSerializationMode)), "SchemaSerializationMode", MemberAttributes.Public | MemberAttributes.Override);

            property.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(BrowsableAttribute).FullName, CodeGenHelper.Primitive(true)));
            property.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(DesignerSerializationVisibilityAttribute).FullName, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Visible")));
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "_schemaSerializationMode")));
            property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), "_schemaSerializationMode"), CodeGenHelper.Argument("value")));
            dataSourceClass.Members.Add(property);
        }
コード例 #8
0
 internal void AddTableProperties(CodeTypeDeclaration dataSourceClass)
 {
     if (this.tables != null)
     {
         foreach (DesignTable table in this.tables)
         {
             string             generatorTableClassName = table.GeneratorTableClassName;
             string             generatorTablePropName  = table.GeneratorTablePropName;
             string             generatorTableVarName   = table.GeneratorTableVarName;
             CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(generatorTableClassName), generatorTablePropName, MemberAttributes.Public | MemberAttributes.Final);
             property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.Browsable", CodeGenHelper.Primitive(false)));
             property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerSerializationVisibility", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Content")));
             property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName)));
             dataSourceClass.Members.Add(property);
         }
     }
 }
 private void AddInitAdapterCommands(CodeMemberMethod method)
 {
     if (this.designTable.DeleteCommand != null)
     {
         CodeExpression commandExpression = CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), "DeleteCommand");
         this.AddCommandInitStatements(method.Statements, commandExpression, this.designTable.DeleteCommand, this.providerFactory, false);
     }
     if (this.designTable.InsertCommand != null)
     {
         CodeExpression expression2 = CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), "InsertCommand");
         this.AddCommandInitStatements(method.Statements, expression2, this.designTable.InsertCommand, this.providerFactory, false);
     }
     if (this.designTable.UpdateCommand != null)
     {
         CodeExpression expression3 = CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), "UpdateCommand");
         this.AddCommandInitStatements(method.Statements, expression3, this.designTable.UpdateCommand, this.providerFactory, false);
     }
 }
        private void AddInitAdapter(CodeTypeDeclaration dataComponentClass)
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), DataComponentNameHandler.InitAdapter, MemberAttributes.Private | MemberAttributes.Final);

            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), CodeGenHelper.New(CodeGenHelper.GlobalType(this.providerFactory.CreateDataAdapter().GetType()), new CodeExpression[0])));
            if ((this.designTable.Mappings != null) && (this.designTable.Mappings.Count > 0))
            {
                method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(DataTableMapping)), "tableMapping", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(DataTableMapping)), new CodeExpression[0])));
                method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("tableMapping"), "SourceTable"), CodeGenHelper.Str("Table")));
                method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("tableMapping"), "DataSetTable"), CodeGenHelper.Str(this.designTable.Name)));
                foreach (DataColumnMapping mapping in this.designTable.Mappings)
                {
                    method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("tableMapping"), "ColumnMappings"), "Add", new CodeExpression[] { CodeGenHelper.Str(mapping.SourceColumn), CodeGenHelper.Str(mapping.DataSetColumn) })));
                }
                method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), "TableMappings"), "Add", new CodeExpression[] { CodeGenHelper.Variable("tableMapping") })));
            }
            this.AddInitAdapterCommands(method);
            dataComponentClass.Members.Add(method);
        }
        private void AddCommandCollectionMembers(CodeTypeDeclaration dataComponentClass, bool isFunctionsDataComponent)
        {
            Type type = null;

            if (isFunctionsDataComponent)
            {
                type = typeof(IDbCommand);
            }
            else
            {
                type = this.providerFactory.CreateCommand().GetType();
            }
            dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(type, 1), DataComponentNameHandler.SelectCmdCollectionVariableName));
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(type, 1), DataComponentNameHandler.SelectCmdCollectionPropertyName, MemberAttributes.Family | MemberAttributes.Final);

            property.GetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), DataComponentNameHandler.InitCmdCollection, new CodeExpression[0])) }));
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName)));
            dataComponentClass.Members.Add(property);
        }
        private void AddInitConnection(CodeTypeDeclaration dataComponentClass)
        {
            IDesignConnection connection = this.designTable.Connection;
            CodeMemberMethod  method     = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), DataComponentNameHandler.InitConnection, MemberAttributes.Private | MemberAttributes.Final);

            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), CodeGenHelper.New(CodeGenHelper.GlobalType(this.providerFactory.CreateConnection().GetType()), new CodeExpression[0])));
            CodeExpression right = null;

            if (connection.PropertyReference == null)
            {
                right = CodeGenHelper.Str(connection.ConnectionStringObject.ToFullString());
            }
            else
            {
                right = connection.PropertyReference;
            }
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), "ConnectionString"), right));
            dataComponentClass.Members.Add(method);
        }
        private void AddAdapterMembers(CodeTypeDeclaration dataComponentClass)
        {
            Type            type  = this.providerFactory.CreateDataAdapter().GetType();
            CodeMemberField field = CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.AdapterVariableName);

            field.UserData.Add("WithEvents", true);
            dataComponentClass.Members.Add(field);
            CodeMemberProperty property = null;

            if (this.generateHierarchicalUpdate)
            {
                property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.AdapterPropertyName, MemberAttributes.FamilyOrAssembly | MemberAttributes.Final);
            }
            else
            {
                property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.AdapterPropertyName, MemberAttributes.Private | MemberAttributes.Final);
            }
            property.GetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), DataComponentNameHandler.InitAdapter, new CodeExpression[0])) }));
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.AdapterVariableName)));
            dataComponentClass.Members.Add(property);
        }
        private void AddConnectionMembers(CodeTypeDeclaration dataComponentClass)
        {
            Type             type     = this.providerFactory.CreateConnection().GetType();
            MemberAttributes modifier = ((DesignConnection)this.designTable.Connection).Modifier;

            dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.DefaultConnectionVariableName));
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.DefaultConnectionPropertyName, modifier | MemberAttributes.Final);

            property.GetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), DataComponentNameHandler.InitConnection, new CodeExpression[0])) }));
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName)));
            property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), CodeGenHelper.Argument("value")));
            property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "InsertCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "InsertCommand"), "Connection"), CodeGenHelper.Argument("value"))));
            property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "DeleteCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "DeleteCommand"), "Connection"), CodeGenHelper.Argument("value"))));
            property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "UpdateCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "UpdateCommand"), "Connection"), CodeGenHelper.Argument("value"))));
            int            count          = this.designTable.Sources.Count;
            CodeStatement  initStmt       = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), "i", CodeGenHelper.Primitive(0));
            CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), "Length"));
            CodeStatement  incrementStmt  = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1)));
            CodeExpression left           = CodeGenHelper.Property(CodeGenHelper.Cast(CodeGenHelper.GlobalType(this.providerFactory.CreateCommand().GetType()), CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i"))), "Connection");
            CodeStatement  statement3     = CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i")), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(left, CodeGenHelper.Argument("value")));

            property.SetStatements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 }));
            dataComponentClass.Members.Add(property);
        }
コード例 #15
0
        internal void AddRowColumnProperties(CodeTypeDeclaration rowClass)
        {
            bool   flag = false;
            string generatorRowClassName = this.codeGenerator.TableHandler.Tables[this.table.TableName].GeneratorRowClassName;
            string generatorTableVarName = this.codeGenerator.TableHandler.Tables[this.table.TableName].GeneratorTableVarName;

            foreach (DesignColumn column in this.columns)
            {
                CodeExpression     expression;
                CodeExpression     expression2;
                DataColumn         dataColumn = column.DataColumn;
                Type               dataType   = dataColumn.DataType;
                string             generatorColumnPropNameInRow   = column.GeneratorColumnPropNameInRow;
                string             generatorColumnPropNameInTable = column.GeneratorColumnPropNameInTable;
                GenericNameHandler handler  = new GenericNameHandler(new string[] { generatorColumnPropNameInRow }, this.codeGenerator.CodeProvider);
                CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(dataType), generatorColumnPropNameInRow, MemberAttributes.Public | MemberAttributes.Final);
                CodeStatement      tryStmnt = CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.GlobalType(dataType), CodeGenHelper.Indexer(CodeGenHelper.This(), CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName), generatorColumnPropNameInTable))));
                if (!dataColumn.AllowDBNull)
                {
                    goto Label_0440;
                }
                string str5 = (string)dataColumn.ExtendedProperties["nullValue"];
                switch (str5)
                {
                case null:
                case "_throw":
                    tryStmnt = CodeGenHelper.Try(tryStmnt, CodeGenHelper.Catch(CodeGenHelper.GlobalType(typeof(InvalidCastException)), handler.AddNameToList("e"), CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(StrongTypingException)), System.Design.SR.GetString("CG_ColumnIsDBNull", new object[] { dataColumn.ColumnName, this.table.TableName }), handler.GetNameFromList("e"))));
                    goto Label_0440;

                default:
                {
                    expression = null;
                    switch (str5)
                    {
                    case "_null":
                        if (dataColumn.DataType.IsSubclassOf(typeof(System.ValueType)))
                        {
                            this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_TypeCantBeNull", new object[] { dataColumn.ColumnName, dataColumn.DataType.Name }), ProblemSeverity.NonFatalError, column));
                            continue;
                        }
                        expression2 = CodeGenHelper.Primitive(null);
                        goto Label_03AE;

                    case "_empty":
                        if (dataColumn.DataType == typeof(string))
                        {
                            expression2 = CodeGenHelper.Property(CodeGenHelper.TypeExpr(CodeGenHelper.GlobalType(dataColumn.DataType)), "Empty");
                        }
                        else
                        {
                            expression2 = CodeGenHelper.Field(CodeGenHelper.TypeExpr(CodeGenHelper.Type(generatorRowClassName)), generatorColumnPropNameInRow + "_nullValue");
                            ConstructorInfo constructor = dataColumn.DataType.GetConstructor(new Type[] { typeof(string) });
                            if (constructor == null)
                            {
                                this.codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_NoCtor0", new object[] { dataColumn.ColumnName, dataColumn.DataType.Name }), ProblemSeverity.NonFatalError, column));
                                continue;
                            }
                            constructor.Invoke(new object[0]);
                            expression = CodeGenHelper.New(CodeGenHelper.Type(dataColumn.DataType), new CodeExpression[0]);
                        }
                        goto Label_03AE;
                    }
                    if (!flag)
                    {
                        this.table.NewRow();
                        flag = true;
                    }
                    object             valueObj = this.codeGenerator.RowHandler.RowGenerator.ConvertXmlToObject.Invoke(dataColumn, new object[] { str5 });
                    DSGeneratorProblem problem  = CodeGenHelper.GenerateValueExprAndFieldInit(column, valueObj, str5, generatorRowClassName, generatorColumnPropNameInRow + "_nullValue", out expression2, out expression);
                    if (problem != null)
                    {
                        this.codeGenerator.ProblemList.Add(problem);
                        continue;
                    }
                    break;
                }
                }
                Label_03AE :;
                tryStmnt = CodeGenHelper.If(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Is" + generatorColumnPropNameInRow + "Null"), new CodeStatement[] { CodeGenHelper.Return(expression2) }, new CodeStatement[] { tryStmnt });
                if (expression != null)
                {
                    CodeMemberField field = CodeGenHelper.FieldDecl(CodeGenHelper.Type(dataColumn.DataType.FullName), generatorColumnPropNameInRow + "_nullValue");
                    field.Attributes     = MemberAttributes.Private | MemberAttributes.Static;
                    field.InitExpression = expression;
                    rowClass.Members.Add(field);
                }
Label_0440:
                property.GetStatements.Add(tryStmnt);
                property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Indexer(CodeGenHelper.This(), CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName), generatorColumnPropNameInTable)), CodeGenHelper.Value()));
                rowClass.Members.Add(property);
                if (dataColumn.AllowDBNull)
                {
                    string           name   = MemberNameValidator.GenerateIdName("Is" + generatorColumnPropNameInRow + "Null", this.codeGenerator.CodeProvider, false);
                    CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(bool)), name, MemberAttributes.Public | MemberAttributes.Final);
                    method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.This(), "IsNull", CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName), generatorColumnPropNameInTable))));
                    rowClass.Members.Add(method);
                    name = MemberNameValidator.GenerateIdName("Set" + generatorColumnPropNameInRow + "Null", this.codeGenerator.CodeProvider, false);
                    CodeMemberMethod method2 = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), name, MemberAttributes.Public | MemberAttributes.Final);
                    method2.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Indexer(CodeGenHelper.This(), CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName), generatorColumnPropNameInTable)), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(Convert)), "DBNull")));
                    rowClass.Members.Add(method2);
                }
            }
        }
コード例 #16
0
        private CodeMemberMethod GetTypedTableSchema()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaComplexType)), "GetTypedTableSchema", MemberAttributes.Public | MemberAttributes.Static);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaSet)), "xs"));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaComplexType)), "type", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaComplexType)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaSequence)), "sequence", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaSequence)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.codeGenerator.DataSourceName), "ds", CodeGenHelper.New(CodeGenHelper.Type(this.codeGenerator.DataSourceName), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaAny)), "any1", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaAny)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any1"), "Namespace"), CodeGenHelper.Str("http://www.w3.org/2001/XMLSchema")));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any1"), "MinOccurs"), CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(decimal)), new CodeExpression[] { CodeGenHelper.Primitive(0) })));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any1"), "MaxOccurs"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(decimal)), "MaxValue")));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any1"), "ProcessContents"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(XmlSchemaContentProcessing)), "Lax")));
            method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("sequence"), "Items"), "Add", new CodeExpression[] { CodeGenHelper.Variable("any1") })));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaAny)), "any2", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaAny)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any2"), "Namespace"), CodeGenHelper.Str("urn:schemas-microsoft-com:xml-diffgram-v1")));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any2"), "MinOccurs"), CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(decimal)), new CodeExpression[] { CodeGenHelper.Primitive(1) })));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any2"), "ProcessContents"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(XmlSchemaContentProcessing)), "Lax")));
            method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("sequence"), "Items"), "Add", new CodeExpression[] { CodeGenHelper.Variable("any2") })));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaAttribute)), "attribute1", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaAttribute)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("attribute1"), "Name"), CodeGenHelper.Primitive("namespace")));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("attribute1"), "FixedValue"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Namespace")));
            method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("type"), "Attributes"), "Add", new CodeExpression[] { CodeGenHelper.Variable("attribute1") })));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaAttribute)), "attribute2", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaAttribute)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("attribute2"), "Name"), CodeGenHelper.Primitive("tableTypeName")));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("attribute2"), "FixedValue"), CodeGenHelper.Str(this.designTable.GeneratorTableClassName)));
            method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("type"), "Attributes"), "Add", new CodeExpression[] { CodeGenHelper.Variable("attribute2") })));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("type"), "Particle"), CodeGenHelper.Variable("sequence")));
            DatasetMethodGenerator.GetSchemaIsInCollection(method.Statements, "ds", "xs");
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable("type")));
            return(method);
        }
        private void AddInitCommandCollection(CodeTypeDeclaration dataComponentClass, bool isFunctionsDataComponent)
        {
            int count = this.designTable.Sources.Count;

            if (!isFunctionsDataComponent)
            {
                count++;
            }
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), DataComponentNameHandler.InitCmdCollection, MemberAttributes.Private | MemberAttributes.Final);
            Type             type   = null;

            if (isFunctionsDataComponent)
            {
                type = typeof(IDbCommand);
            }
            else
            {
                type = this.providerFactory.CreateCommand().GetType();
            }
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.NewArray(CodeGenHelper.GlobalType(type), count)));
            if ((!isFunctionsDataComponent && (this.designTable.MainSource != null)) && (this.designTable.MainSource is DbSource))
            {
                DbSourceCommand activeCommand = ((DbSource)this.designTable.MainSource).GetActiveCommand();
                if (activeCommand != null)
                {
                    CodeExpression commandExpression = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(0));
                    this.AddCommandInitStatements(method.Statements, commandExpression, activeCommand, this.providerFactory, isFunctionsDataComponent);
                }
            }
            if (this.designTable.Sources != null)
            {
                int primitive = 0;
                if (isFunctionsDataComponent)
                {
                    primitive--;
                }
                foreach (Source source2 in this.designTable.Sources)
                {
                    DbSource source3 = source2 as DbSource;
                    primitive++;
                    if (source3 != null)
                    {
                        DbProviderFactory providerFactory = this.providerFactory;
                        if (source3.Connection != null)
                        {
                            providerFactory = ProviderManager.GetFactory(source3.Connection.Provider);
                        }
                        if (providerFactory != null)
                        {
                            DbSourceCommand command = source3.GetActiveCommand();
                            if (command != null)
                            {
                                CodeExpression expression2 = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(primitive));
                                this.AddCommandInitStatements(method.Statements, expression2, command, providerFactory, isFunctionsDataComponent);
                            }
                        }
                    }
                }
            }
            dataComponentClass.Members.Add(method);
        }
コード例 #18
0
        private CodeMemberMethod SchemaChangedMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "SchemaChanged", MemberAttributes.Private);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(object)), "sender"));
            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(CollectionChangeEventArgs)), "e"));
            method.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Argument("e"), "Action"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(CollectionChangeAction)), "Remove")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars"))));
            return(method);
        }
コード例 #19
0
        private CodeMemberProperty TablesProperty()
        {
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataTableCollection)), DataSourceNameHandler.TablesPropertyName, MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Final);

            property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerSerializationVisibilityAttribute", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Hidden")));
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables")));
            return(property);
        }
コード例 #20
0
        private void InitClassAndInitVarsMethods(out CodeMemberMethod initClassMethod, out CodeMemberMethod initVarsMethod)
        {
            initClassMethod = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitClass", MemberAttributes.Private);
            initVarsMethod  = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitVars", MemberAttributes.Assembly | MemberAttributes.Final);
            initVarsMethod.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(bool)), "initTable"));
            initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "DataSetName"), CodeGenHelper.Str(this.dataSet.DataSetName)));
            initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Prefix"), CodeGenHelper.Str(this.dataSet.Prefix)));
            if (namespaceProperty.ShouldSerializeValue(this.dataSet))
            {
                initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Namespace"), CodeGenHelper.Str(this.dataSet.Namespace)));
            }
            if (localeProperty.ShouldSerializeValue(this.dataSet))
            {
                initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Locale"), CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(CultureInfo)), new CodeExpression[] { CodeGenHelper.Str(this.dataSet.Locale.ToString()) })));
            }
            if (caseSensitiveProperty.ShouldSerializeValue(this.dataSet))
            {
                initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "CaseSensitive"), CodeGenHelper.Primitive(this.dataSet.CaseSensitive)));
            }
            initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "EnforceConstraints"), CodeGenHelper.Primitive(this.dataSet.EnforceConstraints)));
            initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "SchemaSerializationMode"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), this.dataSource.SchemaSerializationMode.ToString())));
            foreach (DesignTable table in this.codeGenerator.TableHandler.Tables)
            {
                CodeExpression expression = CodeGenHelper.Field(CodeGenHelper.This(), table.GeneratorTableVarName);
                if (this.TableContainsExpressions(table))
                {
                    initClassMethod.Statements.Add(CodeGenHelper.Assign(expression, CodeGenHelper.New(CodeGenHelper.Type(table.GeneratorTableClassName), new CodeExpression[] { CodeGenHelper.Primitive(false) })));
                }
                else
                {
                    initClassMethod.Statements.Add(CodeGenHelper.Assign(expression, CodeGenHelper.New(CodeGenHelper.Type(table.GeneratorTableClassName), new CodeExpression[0])));
                }
                initClassMethod.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"), "Add", expression));
                initVarsMethod.Statements.Add(CodeGenHelper.Assign(expression, CodeGenHelper.Cast(CodeGenHelper.Type(table.GeneratorTableClassName), CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"), CodeGenHelper.Str(table.Name)))));
                initVarsMethod.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Variable("initTable"), CodeGenHelper.Primitive(true)), new CodeStatement[] { CodeGenHelper.If(CodeGenHelper.IdNotEQ(expression, CodeGenHelper.Primitive(null)), CodeGenHelper.Stm(CodeGenHelper.MethodCall(expression, "InitVars"))) }));
            }
            CodeExpression left = null;

            foreach (DesignTable table2 in this.codeGenerator.TableHandler.Tables)
            {
                DataTable dataTable = table2.DataTable;
                foreach (Constraint constraint in dataTable.Constraints)
                {
                    if (constraint is ForeignKeyConstraint)
                    {
                        ForeignKeyConstraint      constraint2 = (ForeignKeyConstraint)constraint;
                        CodeArrayCreateExpression expression3 = new CodeArrayCreateExpression(CodeGenHelper.GlobalType(typeof(DataColumn)), 0);
                        foreach (DataColumn column in constraint2.Columns)
                        {
                            expression3.Initializers.Add(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), this.codeGenerator.TableHandler.Tables[column.Table.TableName].GeneratorTableVarName), this.codeGenerator.TableHandler.Tables[column.Table.TableName].DesignColumns[column.ColumnName].GeneratorColumnPropNameInTable));
                        }
                        CodeArrayCreateExpression expression4 = new CodeArrayCreateExpression(CodeGenHelper.GlobalType(typeof(DataColumn)), 0);
                        foreach (DataColumn column2 in constraint2.RelatedColumns)
                        {
                            expression4.Initializers.Add(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), this.codeGenerator.TableHandler.Tables[column2.Table.TableName].GeneratorTableVarName), this.codeGenerator.TableHandler.Tables[column2.Table.TableName].DesignColumns[column2.ColumnName].GeneratorColumnPropNameInTable));
                        }
                        if (left == null)
                        {
                            initClassMethod.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(ForeignKeyConstraint)), "fkc"));
                            left = CodeGenHelper.Variable("fkc");
                        }
                        initClassMethod.Statements.Add(CodeGenHelper.Assign(left, CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(ForeignKeyConstraint)), new CodeExpression[] { CodeGenHelper.Str(constraint2.ConstraintName), expression4, expression3 })));
                        initClassMethod.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), this.codeGenerator.TableHandler.Tables[dataTable.TableName].GeneratorTableVarName), "Constraints"), "Add", left));
                        string field = constraint2.AcceptRejectRule.ToString();
                        string str2  = constraint2.DeleteRule.ToString();
                        string str3  = constraint2.UpdateRule.ToString();
                        initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(left, "AcceptRejectRule"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(constraint2.AcceptRejectRule.GetType()), field)));
                        initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(left, "DeleteRule"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(constraint2.DeleteRule.GetType()), str2)));
                        initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(left, "UpdateRule"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(constraint2.UpdateRule.GetType()), str3)));
                    }
                }
            }
            foreach (DesignRelation relation in this.codeGenerator.RelationHandler.Relations)
            {
                DataRelation dataRelation = relation.DataRelation;
                if (dataRelation != null)
                {
                    CodeArrayCreateExpression expression5 = new CodeArrayCreateExpression(CodeGenHelper.GlobalType(typeof(DataColumn)), 0);
                    string generatorTableVarName          = relation.ParentDesignTable.GeneratorTableVarName;
                    foreach (DataColumn column3 in dataRelation.ParentColumns)
                    {
                        expression5.Initializers.Add(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName), this.codeGenerator.TableHandler.Tables[column3.Table.TableName].DesignColumns[column3.ColumnName].GeneratorColumnPropNameInTable));
                    }
                    CodeArrayCreateExpression expression6 = new CodeArrayCreateExpression(CodeGenHelper.GlobalType(typeof(DataColumn)), 0);
                    string str5 = relation.ChildDesignTable.GeneratorTableVarName;
                    foreach (DataColumn column4 in dataRelation.ChildColumns)
                    {
                        expression6.Initializers.Add(CodeGenHelper.Property(CodeGenHelper.Field(CodeGenHelper.This(), str5), this.codeGenerator.TableHandler.Tables[column4.Table.TableName].DesignColumns[column4.ColumnName].GeneratorColumnPropNameInTable));
                    }
                    CodeExpression expression7 = CodeGenHelper.Field(CodeGenHelper.This(), this.codeGenerator.RelationHandler.Relations[dataRelation.RelationName].GeneratorRelationVarName);
                    initClassMethod.Statements.Add(CodeGenHelper.Assign(expression7, CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(DataRelation)), new CodeExpression[] { CodeGenHelper.Str(dataRelation.RelationName), expression5, expression6, CodeGenHelper.Primitive(false) })));
                    if (dataRelation.Nested)
                    {
                        initClassMethod.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression7, "Nested"), CodeGenHelper.Primitive(true)));
                    }
                    ExtendedPropertiesHandler.CodeGenerator = this.codeGenerator;
                    ExtendedPropertiesHandler.AddExtendedProperties(relation, expression7, initClassMethod.Statements, dataRelation.ExtendedProperties);
                    initClassMethod.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Relations"), "Add", expression7));
                    initVarsMethod.Statements.Add(CodeGenHelper.Assign(expression7, CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), "Relations"), CodeGenHelper.Str(dataRelation.RelationName))));
                }
            }
            ExtendedPropertiesHandler.CodeGenerator = this.codeGenerator;
            ExtendedPropertiesHandler.AddExtendedProperties(this.dataSource, CodeGenHelper.This(), initClassMethod.Statements, this.dataSet.ExtendedProperties);
        }
コード例 #21
0
        private CodeMemberMethod ReadXmlSerializableMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "ReadXmlSerializable", MemberAttributes.Family | MemberAttributes.Override);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(XmlReader)), "reader"));
            ArrayList list  = new ArrayList();
            ArrayList list2 = new ArrayList();

            list.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Reset", new CodeExpression[0])));
            list.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(DataSet)), "ds", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(DataSet)), new CodeExpression[0])));
            list.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("ds"), "ReadXml", new CodeExpression[] { CodeGenHelper.Argument("reader") })));
            foreach (DesignTable table in this.codeGenerator.TableHandler.Tables)
            {
                list.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Tables"), CodeGenHelper.Str(table.Name)), CodeGenHelper.Primitive(null)), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"), "Add", CodeGenHelper.New(CodeGenHelper.Type(table.GeneratorTableClassName), new CodeExpression[] { CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Tables"), CodeGenHelper.Str(table.Name)) })))));
            }
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "DataSetName"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "DataSetName")));
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Prefix"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Prefix")));
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Namespace"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Namespace")));
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Locale"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Locale")));
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "CaseSensitive"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "CaseSensitive")));
            list.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "EnforceConstraints"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "EnforceConstraints")));
            list.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Merge", new CodeExpression[] { CodeGenHelper.Variable("ds"), CodeGenHelper.Primitive(false), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(MissingSchemaAction)), "Add") })));
            list.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars")));
            list2.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "ReadXml", new CodeExpression[] { CodeGenHelper.Argument("reader") })));
            list2.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars")));
            method.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.MethodCall(CodeGenHelper.This(), "DetermineSchemaSerializationMode", new CodeExpression[] { CodeGenHelper.Argument("reader") }), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), "IncludeSchema")), (CodeStatement[])list.ToArray(typeof(CodeStatement)), (CodeStatement[])list2.ToArray(typeof(CodeStatement))));
            return(method);
        }
コード例 #22
0
        protected void AddSetParameterStatements(DesignParameter parameter, string parameterName, DesignParameter isNullParameter, CodeExpression cmdExpression, int parameterIndex, int isNullParameterIndex, IList statements)
        {
            Type parameterUrtType    = this.GetParameterUrtType(parameter);
            CodeCastExpression right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Argument(parameterName));

            right.UserData.Add("CastIsBoxing", true);
            CodeCastExpression expression2 = null;
            CodeCastExpression expression3 = null;

            if ((this.codeGenerator != null) && CodeGenHelper.IsGeneratingJSharpCode(this.codeGenerator.CodeProvider))
            {
                expression2 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(0));
                expression2.UserData.Add("CastIsBoxing", true);
                expression3 = new CodeCastExpression(typeof(int), CodeGenHelper.Primitive(1));
                expression3.UserData.Add("CastIsBoxing", true);
            }
            else
            {
                expression2 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(0));
                expression3 = new CodeCastExpression(typeof(object), CodeGenHelper.Primitive(1));
            }
            CodeExpression left        = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(parameterIndex)), "Value");
            CodeExpression expression5 = null;

            if (isNullParameter != null)
            {
                expression5 = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(cmdExpression, "Parameters"), CodeGenHelper.Primitive(isNullParameterIndex)), "Value");
            }
            int num = (isNullParameter == null) ? 1 : 2;

            CodeStatement[] trueStms  = new CodeStatement[num];
            CodeStatement[] falseStms = new CodeStatement[num];
            if (parameter.AllowDbNull && parameterUrtType.IsValueType)
            {
                right = new CodeCastExpression(parameterUrtType, CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "Value"));
                right.UserData.Add("CastIsBoxing", true);
                trueStms[0]  = CodeGenHelper.Assign(left, right);
                falseStms[0] = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
                if (isNullParameter != null)
                {
                    trueStms[1]  = trueStms[0];
                    falseStms[1] = falseStms[0];
                    trueStms[0]  = CodeGenHelper.Assign(expression5, expression2);
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression3);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Argument(parameterName), "HasValue"), CodeGenHelper.Primitive(true)), trueStms, falseStms));
            }
            else if (parameter.AllowDbNull && !parameterUrtType.IsValueType)
            {
                trueStms[0]  = CodeGenHelper.Assign(left, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DBNull)), "Value"));
                falseStms[0] = CodeGenHelper.Assign(left, right);
                if (isNullParameter != null)
                {
                    trueStms[1]  = trueStms[0];
                    falseStms[1] = falseStms[0];
                    trueStms[0]  = CodeGenHelper.Assign(expression5, expression3);
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), trueStms, falseStms));
            }
            else if (!parameter.AllowDbNull && !parameterUrtType.IsValueType)
            {
                CodeStatement[] statementArray3 = new CodeStatement[] { CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(ArgumentNullException)), parameterName) };
                falseStms[0] = CodeGenHelper.Assign(left, right);
                if (isNullParameter != null)
                {
                    falseStms[1] = falseStms[0];
                    falseStms[0] = CodeGenHelper.Assign(expression5, expression2);
                }
                statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Argument(parameterName), CodeGenHelper.Primitive(null)), statementArray3, falseStms));
            }
            else if (!parameter.AllowDbNull && parameterUrtType.IsValueType)
            {
                if (isNullParameter != null)
                {
                    statements.Add(CodeGenHelper.Assign(expression5, expression2));
                }
                statements.Add(CodeGenHelper.Assign(left, right));
            }
        }
コード例 #23
0
        private CodeConstructor DeserializingConstructor()
        {
            CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Family);

            constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(SerializationInfo)), "info"));
            constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(StreamingContext)), "context"));
            constructor.BaseConstructorArgs.AddRange(new CodeExpression[] { CodeGenHelper.Argument("info"), CodeGenHelper.Argument("context"), CodeGenHelper.Primitive(false) });
            List <CodeStatement> list = new List <CodeStatement>();

            list.AddRange(new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars", CodeGenHelper.Primitive(false))), CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(CollectionChangeEventHandler)), "schemaChangedHandler1", new CodeDelegateCreateExpression(CodeGenHelper.GlobalType(typeof(CollectionChangeEventHandler)), CodeGenHelper.This(), "SchemaChanged")), new CodeAttachEventStatement(new CodeEventReferenceExpression(CodeGenHelper.Property(CodeGenHelper.This(), "Tables"), "CollectionChanged"), CodeGenHelper.Variable("schemaChangedHandler1")), new CodeAttachEventStatement(new CodeEventReferenceExpression(CodeGenHelper.Property(CodeGenHelper.This(), "Relations"), "CollectionChanged"), CodeGenHelper.Variable("schemaChangedHandler1")) });
            if (this.initExpressionsMethod != null)
            {
                list.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.MethodCall(CodeGenHelper.This(), "DetermineSchemaSerializationMode", new CodeExpression[] { CodeGenHelper.Argument("info"), CodeGenHelper.Argument("context") }), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), "ExcludeSchema")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitExpressions"))));
            }
            list.Add(CodeGenHelper.Return());
            constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.MethodCall(CodeGenHelper.This(), "IsBinarySerialized", new CodeExpression[] { CodeGenHelper.Argument("info"), CodeGenHelper.Argument("context") }), CodeGenHelper.Primitive(true)), list.ToArray()));
            constructor.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(string)), "strSchema", CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(string)), CodeGenHelper.MethodCall(CodeGenHelper.Argument("info"), "GetValue", new CodeExpression[] { CodeGenHelper.Str("XmlSchema"), CodeGenHelper.TypeOf(CodeGenHelper.GlobalType(typeof(string))) }))));
            ArrayList list2 = new ArrayList();
            ArrayList list3 = new ArrayList();

            list2.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(DataSet)), "ds", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(DataSet)), new CodeExpression[0])));
            list2.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("ds"), "ReadXmlSchema", new CodeExpression[] { CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlTextReader)), new CodeExpression[] { CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(StringReader)), new CodeExpression[] { CodeGenHelper.Variable("strSchema") }) }) })));
            foreach (DesignTable table in this.codeGenerator.TableHandler.Tables)
            {
                list2.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Tables"), CodeGenHelper.Str(table.Name)), CodeGenHelper.Primitive(null)), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"), "Add", CodeGenHelper.New(CodeGenHelper.Type(table.GeneratorTableClassName), new CodeExpression[] { CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Tables"), CodeGenHelper.Str(table.Name)) })))));
            }
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "DataSetName"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "DataSetName")));
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Prefix"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Prefix")));
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Namespace"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Namespace")));
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Locale"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Locale")));
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "CaseSensitive"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "CaseSensitive")));
            list2.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "EnforceConstraints"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "EnforceConstraints")));
            list2.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Merge", new CodeExpression[] { CodeGenHelper.Variable("ds"), CodeGenHelper.Primitive(false), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(MissingSchemaAction)), "Add") })));
            list2.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars")));
            list3.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "ReadXmlSchema", new CodeExpression[] { CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlTextReader)), new CodeExpression[] { CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(StringReader)), new CodeExpression[] { CodeGenHelper.Variable("strSchema") }) }) })));
            if (this.initExpressionsMethod != null)
            {
                list3.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitExpressions")));
            }
            constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.MethodCall(CodeGenHelper.This(), "DetermineSchemaSerializationMode", new CodeExpression[] { CodeGenHelper.Argument("info"), CodeGenHelper.Argument("context") }), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), "IncludeSchema")), (CodeStatement[])list2.ToArray(typeof(CodeStatement)), (CodeStatement[])list3.ToArray(typeof(CodeStatement))));
            constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "GetSerializationData", new CodeExpression[] { CodeGenHelper.Argument("info"), CodeGenHelper.Argument("context") }));
            constructor.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(CollectionChangeEventHandler)), "schemaChangedHandler", new CodeDelegateCreateExpression(CodeGenHelper.GlobalType(typeof(CollectionChangeEventHandler)), CodeGenHelper.This(), "SchemaChanged")));
            constructor.Statements.Add(new CodeAttachEventStatement(new CodeEventReferenceExpression(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"), "CollectionChanged"), CodeGenHelper.Variable("schemaChangedHandler")));
            constructor.Statements.Add(new CodeAttachEventStatement(new CodeEventReferenceExpression(CodeGenHelper.Property(CodeGenHelper.This(), "Relations"), "CollectionChanged"), CodeGenHelper.Variable("schemaChangedHandler")));
            return(constructor);
        }
コード例 #24
0
 internal static CodeStatement SetCommandTypeStatement(CodeExpression commandExpression, CommandType commandType)
 {
     return(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "CommandType"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(CommandType)), commandType.ToString())));
 }
コード例 #25
0
 private static CodeExpression NewParameter(DesignParameter parameter, Type parameterType, Type typeEnumType, string typeEnumValue)
 {
     if (parameterType == typeof(SqlParameter))
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty), CodeGenHelper.Str(string.Empty) }));
     }
     if (parameterType == SqlCeParameterType)
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Primitive(parameter.IsNullable), CodeGenHelper.Primitive(parameter.Precision), CodeGenHelper.Primitive(parameter.Scale), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(null) }));
     }
     if (parameterType == typeof(OracleParameter))
     {
         return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) }));
     }
     return(CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[] { CodeGenHelper.Str(parameter.ParameterName), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeEnumType), typeEnumValue), CodeGenHelper.Primitive(parameter.Size), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString()), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Precision)), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(byte)), CodeGenHelper.Primitive(parameter.Scale)), CodeGenHelper.Str(parameter.SourceColumn), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString()), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping), CodeGenHelper.Primitive(null) }));
 }
コード例 #26
0
        private static CodeExpression BuildNewUnknownParameterStatements(DesignParameter parameter, Type parameterType, DbProviderFactory factory, IList statements, CodeExpression parameterVariable)
        {
            if (!ParamVariableDeclared(statements))
            {
                statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(parameterType), "param", CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
                parameterVariable = CodeGenHelper.Variable("param");
            }
            else
            {
                if ((parameterVariable == null) || !(parameterVariable is CodeVariableReferenceExpression))
                {
                    parameterVariable = CodeGenHelper.Variable("param");
                }
                statements.Add(CodeGenHelper.Assign(parameterVariable, CodeGenHelper.New(CodeGenHelper.GlobalType(parameterType), new CodeExpression[0])));
            }
            IDbDataParameter parameter2 = (IDbDataParameter)Activator.CreateInstance(parameterType);

            statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "ParameterName"), CodeGenHelper.Str(parameter.ParameterName)));
            if (parameter.DbType != parameter2.DbType)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "DbType"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DbType)), parameter.DbType.ToString())));
            }
            PropertyInfo providerTypeProperty = ProviderManager.GetProviderTypeProperty(factory);

            if (((providerTypeProperty != null) && (parameter.ProviderType != null)) && (parameter.ProviderType.Length > 0))
            {
                object obj2 = null;
                try
                {
                    obj2 = Enum.Parse(providerTypeProperty.PropertyType, parameter.ProviderType);
                }
                catch
                {
                }
                if (obj2 != null)
                {
                    statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, providerTypeProperty.Name), CodeGenHelper.Field(CodeGenHelper.TypeExpr(CodeGenHelper.GlobalType(providerTypeProperty.PropertyType)), obj2.ToString())));
                }
            }
            if (parameter.Size != parameter2.Size)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Size"), CodeGenHelper.Primitive(parameter.Size)));
            }
            if (parameter.Direction != parameter2.Direction)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Direction"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ParameterDirection)), parameter.Direction.ToString())));
            }
            if (parameter.IsNullable != parameter2.IsNullable)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "IsNullable"), CodeGenHelper.Primitive(parameter.IsNullable)));
            }
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(persistScaleAndPrecisionRegistryKey))
            {
                if (key != null)
                {
                    if (parameter.Precision != parameter2.Precision)
                    {
                        statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Precision"), CodeGenHelper.Primitive(parameter.Precision)));
                    }
                    if (parameter.Scale != parameter2.Scale)
                    {
                        statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "Scale"), CodeGenHelper.Primitive(parameter.Scale)));
                    }
                }
            }
            if (parameter.SourceColumn != parameter2.SourceColumn)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumn"), CodeGenHelper.Str(parameter.SourceColumn)));
            }
            if (parameter.SourceVersion != parameter2.SourceVersion)
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceVersion"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataRowVersion)), parameter.SourceVersion.ToString())));
            }
            if ((parameter2 is DbParameter) && (parameter.SourceColumnNullMapping != ((DbParameter)parameter2).SourceColumnNullMapping))
            {
                statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(parameterVariable, "SourceColumnNullMapping"), CodeGenHelper.Primitive(parameter.SourceColumnNullMapping)));
            }
            return(parameterVariable);
        }
コード例 #27
0
        private void InitClassAndInitVarsMethods(CodeTypeDeclaration tableClass, out CodeMemberMethod tableInitClass, out CodeMemberMethod tableInitVars)
        {
            DataTable dataTable = this.designTable.DataTable;

            tableInitClass = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitClass", MemberAttributes.Private);
            tableInitVars  = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitVars", MemberAttributes.Assembly | MemberAttributes.Final);
            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                DataColumn     column = dataTable.Columns[i];
                string         generatorColumnVarNameInTable = this.codeGenerator.TableHandler.Tables[dataTable.TableName].DesignColumns[column.ColumnName].GeneratorColumnVarNameInTable;
                CodeExpression left = CodeGenHelper.Field(CodeGenHelper.This(), generatorColumnVarNameInTable);
                string         str2 = "Element";
                if (column.ColumnMapping == MappingType.SimpleContent)
                {
                    str2 = "SimpleContent";
                }
                else if (column.ColumnMapping == MappingType.Attribute)
                {
                    str2 = "Attribute";
                }
                else if (column.ColumnMapping == MappingType.Hidden)
                {
                    str2 = "Hidden";
                }
                tableInitClass.Statements.Add(CodeGenHelper.Assign(left, CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(DataColumn)), new CodeExpression[] { CodeGenHelper.Str(column.ColumnName), CodeGenHelper.TypeOf(CodeGenHelper.GlobalType(column.DataType)), CodeGenHelper.Primitive(null), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(MappingType)), str2) })));
                ExtendedPropertiesHandler.CodeGenerator = this.codeGenerator;
                ExtendedPropertiesHandler.AddExtendedProperties(this.designTable.DesignColumns[column.ColumnName], left, tableInitClass.Statements, column.ExtendedProperties);
                tableInitClass.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Base(), "Columns"), "Add", CodeGenHelper.Field(CodeGenHelper.This(), generatorColumnVarNameInTable)));
            }
            for (int j = 0; j < dataTable.Constraints.Count; j++)
            {
                if (dataTable.Constraints[j] is UniqueConstraint)
                {
                    UniqueConstraint constraint   = (UniqueConstraint)dataTable.Constraints[j];
                    DataColumn[]     columns      = constraint.Columns;
                    CodeExpression[] initializers = new CodeExpression[columns.Length];
                    for (int m = 0; m < columns.Length; m++)
                    {
                        initializers[m] = CodeGenHelper.Field(CodeGenHelper.This(), this.codeGenerator.TableHandler.Tables[columns[m].Table.TableName].DesignColumns[columns[m].ColumnName].GeneratorColumnVarNameInTable);
                    }
                    tableInitClass.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Constraints"), "Add", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(UniqueConstraint)), new CodeExpression[] { CodeGenHelper.Str(constraint.ConstraintName), new CodeArrayCreateExpression(CodeGenHelper.GlobalType(typeof(DataColumn)), initializers), CodeGenHelper.Primitive(constraint.IsPrimaryKey) })));
                }
            }
            for (int k = 0; k < dataTable.Columns.Count; k++)
            {
                DataColumn     component   = dataTable.Columns[k];
                string         str3        = this.codeGenerator.TableHandler.Tables[dataTable.TableName].DesignColumns[component.ColumnName].GeneratorColumnVarNameInTable;
                CodeExpression expression2 = CodeGenHelper.Field(CodeGenHelper.This(), str3);
                tableInitVars.Statements.Add(CodeGenHelper.Assign(expression2, CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Base(), "Columns"), CodeGenHelper.Str(component.ColumnName))));
                if (component.AutoIncrement)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "AutoIncrement"), CodeGenHelper.Primitive(true)));
                }
                if (component.AutoIncrementSeed != 0L)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "AutoIncrementSeed"), CodeGenHelper.Primitive(component.AutoIncrementSeed)));
                }
                if (component.AutoIncrementStep != 1L)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "AutoIncrementStep"), CodeGenHelper.Primitive(component.AutoIncrementStep)));
                }
                if (!component.AllowDBNull)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "AllowDBNull"), CodeGenHelper.Primitive(false)));
                }
                if (component.ReadOnly)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "ReadOnly"), CodeGenHelper.Primitive(true)));
                }
                if (component.Unique)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "Unique"), CodeGenHelper.Primitive(true)));
                }
                if (!StringUtil.Empty(component.Prefix))
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "Prefix"), CodeGenHelper.Str(component.Prefix)));
                }
                if (columnNamespaceProperty.ShouldSerializeValue(component))
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "Namespace"), CodeGenHelper.Str(component.Namespace)));
                }
                if (component.Caption != component.ColumnName)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "Caption"), CodeGenHelper.Str(component.Caption)));
                }
                if (component.DefaultValue != DBNull.Value)
                {
                    CodeExpression     valueExpr    = null;
                    CodeExpression     fieldInit    = null;
                    DesignColumn       designColumn = this.codeGenerator.TableHandler.Tables[dataTable.TableName].DesignColumns[component.ColumnName];
                    DSGeneratorProblem problem      = CodeGenHelper.GenerateValueExprAndFieldInit(designColumn, component.DefaultValue, component.DefaultValue, this.designTable.GeneratorTableClassName, str3 + "_defaultValue", out valueExpr, out fieldInit);
                    if (problem != null)
                    {
                        this.codeGenerator.ProblemList.Add(problem);
                    }
                    else
                    {
                        if (fieldInit != null)
                        {
                            CodeMemberField field = CodeGenHelper.FieldDecl(CodeGenHelper.Type(component.DataType.FullName), str3 + "_defaultValue");
                            field.Attributes     = MemberAttributes.Private | MemberAttributes.Static;
                            field.InitExpression = fieldInit;
                            tableClass.Members.Add(field);
                        }
                        CodeCastExpression right = new CodeCastExpression(component.DataType, valueExpr);
                        right.UserData.Add("CastIsBoxing", true);
                        tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "DefaultValue"), right));
                    }
                }
                if (component.MaxLength != -1)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "MaxLength"), CodeGenHelper.Primitive(component.MaxLength)));
                }
                if (component.DateTimeMode != DataSetDateTime.UnspecifiedLocal)
                {
                    tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(expression2, "DateTimeMode"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataSetDateTime)), component.DateTimeMode.ToString())));
                }
            }
            if (caseSensitiveProperty.ShouldSerializeValue(dataTable))
            {
                tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "CaseSensitive"), CodeGenHelper.Primitive(dataTable.CaseSensitive)));
            }
            if ((dataTable.Locale != null) && localeProperty.ShouldSerializeValue(dataTable))
            {
                tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Locale"), CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(CultureInfo)), new CodeExpression[] { CodeGenHelper.Str(dataTable.Locale.ToString()) })));
            }
            if (!StringUtil.Empty(dataTable.Prefix))
            {
                tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Prefix"), CodeGenHelper.Str(dataTable.Prefix)));
            }
            if (namespaceProperty.ShouldSerializeValue(dataTable))
            {
                tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Namespace"), CodeGenHelper.Str(dataTable.Namespace)));
            }
            if (dataTable.MinimumCapacity != 50)
            {
                tableInitClass.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "MinimumCapacity"), CodeGenHelper.Primitive(dataTable.MinimumCapacity)));
            }
            ExtendedPropertiesHandler.CodeGenerator = this.codeGenerator;
            ExtendedPropertiesHandler.AddExtendedProperties(this.designTable, CodeGenHelper.This(), tableInitClass.Statements, dataTable.ExtendedProperties);
        }
コード例 #28
0
        private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
        {
            DataObjectMethodType update = DataObjectMethodType.Update;

            if (base.methodSource.EnableWebMethods)
            {
                CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
                declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
                dbMethod.CustomAttributes.Add(declaration);
            }
            if (base.MethodType != MethodTypeEnum.GenericUpdate)
            {
                if (base.activeCommand == base.methodSource.DeleteCommand)
                {
                    update = DataObjectMethodType.Delete;
                }
                else if (base.activeCommand == base.methodSource.InsertCommand)
                {
                    update = DataObjectMethodType.Insert;
                }
                else if (base.activeCommand == base.methodSource.UpdateCommand)
                {
                    update = DataObjectMethodType.Update;
                }
                dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), update.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(true)) }));
            }
        }
コード例 #29
0
 private bool AddExecuteCommandStatements(IList statements)
 {
     if (base.MethodType == MethodTypeEnum.ColumnParameters)
     {
         CodeStatement[] tryStmnts     = new CodeStatement[1];
         CodeStatement[] finallyStmnts = new CodeStatement[1];
         statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(ConnectionState)), base.nameHandler.AddNameToList("previousConnectionState"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "State")));
         statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.BitwiseAnd(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "State"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "Open"))));
         tryStmnts[0]     = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName, CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "ExecuteNonQuery", new CodeExpression[0]));
         finallyStmnts[0] = CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("previousConnectionState")), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Closed")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "Close")));
         statements.Add(CodeGenHelper.Try(tryStmnts, new CodeCatchClause[0], finallyStmnts));
     }
     else if (StringUtil.EqualValue(base.UpdateParameterTypeReference.BaseType, typeof(DataRow).FullName) && (base.UpdateParameterTypeReference.ArrayRank == 0))
     {
         statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.NewArray(base.UpdateParameterTypeReference, new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName) }) })));
     }
     else if (StringUtil.EqualValue(base.UpdateParameterTypeReference.BaseType, typeof(DataSet).FullName))
     {
         statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName), CodeGenHelper.Str(base.DesignTable.Name) })));
     }
     else
     {
         statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName) })));
     }
     return(true);
 }
コード例 #30
0
        private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
        {
            bool primitive            = false;
            DataObjectMethodType fill = DataObjectMethodType.Fill;

            if (base.methodSource.EnableWebMethods && base.getMethod)
            {
                CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
                declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
                dbMethod.CustomAttributes.Add(declaration);
            }
            if (!base.GeneratePagingMethod && (base.getMethod || (base.ContainerParameterType == typeof(DataTable))))
            {
                if (base.MethodSource == base.DesignTable.MainSource)
                {
                    primitive = true;
                }
                if (base.getMethod)
                {
                    fill = DataObjectMethodType.Select;
                }
                else
                {
                    fill = DataObjectMethodType.Fill;
                }
                dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), fill.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(primitive)) }));
            }
        }