private CodeMemberMethod InitVarsParamLess()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitVars", MemberAttributes.Assembly | MemberAttributes.Final);

            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars", new CodeExpression[] { CodeGenHelper.Primitive(true) }));
            return(method);
        }
        private CodeMemberMethod NewTypedRowMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), NameHandler.FixIdName("New" + this.rowClassName), MemberAttributes.Public | MemberAttributes.Final);

            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(this.rowConcreteClassName), CodeGenHelper.MethodCall(CodeGenHelper.This(), "NewRow"))));
            return(method);
        }
        private CodeMemberMethod GetRowTypeMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(Type)), "GetRowType", MemberAttributes.Family | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.TypeOf(CodeGenHelper.Type(this.rowConcreteClassName))));
            return(method);
        }
        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 CodeMemberMethod CreateInstanceMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(DataTable)), "CreateInstance", MemberAttributes.Family | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.Type(this.tableClassName), new CodeExpression[0])));
            return(method);
        }
        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);
        }
        private CodeMemberMethod ShouldSerializeTablesMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(bool)), "ShouldSerializeTables", MemberAttributes.Family | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Primitive(false)));
            return(method);
        }
Example #8
0
        private CodeMemberMethod GenerateInternal()
        {
            base.returnType = typeof(int);
            CodeMemberMethod dbMethod = null;

            if (base.getMethod)
            {
                dbMethod = CodeGenHelper.MethodDecl(CodeGenHelper.Type(base.ContainerParameterTypeName), base.MethodName, base.methodAttributes);
            }
            else
            {
                dbMethod = CodeGenHelper.MethodDecl(CodeGenHelper.Type(base.returnType), base.MethodName, base.methodAttributes);
            }
            dbMethod.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
            this.AddParametersToMethod(dbMethod);
            if (base.declarationOnly)
            {
                base.AddThrowsClauseIfNeeded(dbMethod);
                return(dbMethod);
            }
            this.AddCustomAttributesToMethod(dbMethod);
            if (this.AddStatementsToMethod(dbMethod))
            {
                return(dbMethod);
            }
            return(null);
        }
        private CodeMemberMethod NewRowFromBuilderMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(DataRow)), "NewRowFromBuilder", MemberAttributes.Family | MemberAttributes.Override);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(DataRowBuilder)), "builder"));
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.Type(this.rowConcreteClassName), new CodeExpression[] { CodeGenHelper.Argument("builder") })));
            return(method);
        }
        private CodeMemberMethod GetEnumeratorMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(IEnumerator)), "GetEnumerator", MemberAttributes.Public);

            method.ImplementationTypes.Add(CodeGenHelper.GlobalType(typeof(IEnumerable)));
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "GetEnumerator")));
            return(method);
        }
        private CodeMemberMethod RemoveRowMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), NameHandler.FixIdName("Remove" + this.rowClassName), MemberAttributes.Public | MemberAttributes.Final);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(this.rowConcreteClassName), "row"));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Remove", CodeGenHelper.Argument("row")));
            return(method);
        }
        private CodeMemberMethod InitializeDerivedDataSet()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitializeDerivedDataSet", MemberAttributes.Family | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "BeginInit"));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitClass"));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "EndInit"));
            return(method);
        }
        private CodeMemberMethod CreateOnRowEventMethod(string eventName, string typedEventName)
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "OnRow" + eventName, MemberAttributes.Family | MemberAttributes.Override);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(DataRowChangeEventArgs)), "e"));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Base(), "OnRow" + eventName, CodeGenHelper.Argument("e")));
            method.Statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Event(typedEventName), CodeGenHelper.Primitive(null)), CodeGenHelper.Stm(CodeGenHelper.DelegateCall(CodeGenHelper.Event(typedEventName), CodeGenHelper.New(CodeGenHelper.Type(this.designTable.GeneratorRowEvArgName), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.Type(this.rowClassName), CodeGenHelper.Property(CodeGenHelper.Argument("e"), "Row")), CodeGenHelper.Property(CodeGenHelper.Argument("e"), "Action") })))));
            return(method);
        }
        private CodeMemberMethod CloneMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(DataTable)), "Clone", MemberAttributes.Public | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.tableClassName), "cln", CodeGenHelper.Cast(CodeGenHelper.Type(this.tableClassName), CodeGenHelper.MethodCall(CodeGenHelper.Base(), "Clone", new CodeExpression[0]))));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Variable("cln"), "InitVars", new CodeExpression[0]));
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable("cln")));
            return(method);
        }
        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);
        }
        private CodeMemberMethod GetSchemaSerializableMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(XmlSchema)), "GetSchemaSerializable", MemberAttributes.Family | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(MemoryStream)), "stream", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(MemoryStream)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "WriteXmlSchema", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlTextWriter)), new CodeExpression[] { CodeGenHelper.Argument("stream"), CodeGenHelper.Primitive(null) })));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Argument("stream"), "Position"), CodeGenHelper.Primitive(0)));
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.GlobalTypeExpr(typeof(XmlSchema)), "Read", new CodeExpression[] { CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlTextReader)), new CodeExpression[] { CodeGenHelper.Argument("stream") }), CodeGenHelper.Primitive(null) })));
            return(method);
        }
        private CodeMemberMethod GenerateInternal()
        {
            DesignParameter   returnParameter = base.GetReturnParameter(base.activeCommand);
            CodeTypeReference type            = null;

            if (base.methodSource.QueryType == QueryType.Scalar)
            {
                base.returnType = base.methodSource.ScalarCallRetval;
                if (base.returnType.IsValueType)
                {
                    type = CodeGenHelper.NullableType(base.returnType);
                }
                else
                {
                    type = CodeGenHelper.Type(base.returnType);
                }
            }
            else if ((base.methodSource.DbObjectType == DbObjectType.Function) && (returnParameter != null))
            {
                base.returnType = base.GetParameterUrtType(returnParameter);
                if (returnParameter.AllowDbNull && base.returnType.IsValueType)
                {
                    type = CodeGenHelper.NullableType(base.returnType);
                }
                else
                {
                    type = CodeGenHelper.Type(base.returnType);
                }
            }
            else
            {
                base.returnType = typeof(int);
                type            = CodeGenHelper.Type(base.returnType);
            }
            CodeMemberMethod dbMethod = null;

            dbMethod = CodeGenHelper.MethodDecl(type, base.MethodName, base.methodAttributes);
            dbMethod.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
            this.AddParametersToMethod(dbMethod);
            if (base.declarationOnly)
            {
                base.AddThrowsClauseIfNeeded(dbMethod);
                return(dbMethod);
            }
            this.AddCustomAttributesToMethod(dbMethod);
            if (this.AddStatementsToMethod(dbMethod))
            {
                return(dbMethod);
            }
            return(null);
        }
        private CodeMemberMethod CloneMethod(CodeMemberMethod initExpressionsMethod)
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(DataSet)), "Clone", MemberAttributes.Public | MemberAttributes.Override);

            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.codeGenerator.DataSourceName), "cln", CodeGenHelper.Cast(CodeGenHelper.Type(this.codeGenerator.DataSourceName), CodeGenHelper.MethodCall(CodeGenHelper.Base(), "Clone", new CodeExpression[0]))));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Variable("cln"), "InitVars", new CodeExpression[0]));
            if (initExpressionsMethod != null)
            {
                method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Variable("cln"), "InitExpressions", new CodeExpression[0]));
            }
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("cln"), "SchemaSerializationMode"), CodeGenHelper.Property(CodeGenHelper.This(), "SchemaSerializationMode")));
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable("cln")));
            return(method);
        }
 private void AddShouldSerializeSingleTableMethods(CodeTypeDeclaration dataSourceClass)
 {
     foreach (DesignTable table in this.codeGenerator.TableHandler.Tables)
     {
         string generatorTablePropName = table.GeneratorTablePropName;
         if ((this.codeGenerator.CodeProvider.IsValidIdentifier(generatorTablePropName) && generatorTablePropName.StartsWith("[", StringComparison.Ordinal)) && generatorTablePropName.EndsWith("]", StringComparison.Ordinal))
         {
             generatorTablePropName = generatorTablePropName.Substring(1, generatorTablePropName.Length - 2);
         }
         string           name   = MemberNameValidator.GenerateIdName("ShouldSerialize" + generatorTablePropName, this.codeGenerator.CodeProvider, false);
         CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(bool)), name, MemberAttributes.Private);
         method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Primitive(false)));
         dataSourceClass.Members.Add(method);
     }
 }
        private CodeMemberMethod GetTypedDataSetSchema()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaComplexType)), "GetTypedDataSetSchema", MemberAttributes.Public | MemberAttributes.Static);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(XmlSchemaSet)), "xs"));
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.dataSource.GeneratorDataSetName), "ds", CodeGenHelper.New(CodeGenHelper.Type(this.dataSource.GeneratorDataSetName), new CodeExpression[0])));
            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.GlobalType(typeof(XmlSchemaAny)), "any", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(XmlSchemaAny)), new CodeExpression[0])));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("any"), "Namespace"), CodeGenHelper.Property(CodeGenHelper.Variable("ds"), "Namespace")));
            method.Statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable("sequence"), "Items"), "Add", new CodeExpression[] { CodeGenHelper.Variable("any") })));
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("type"), "Particle"), CodeGenHelper.Variable("sequence")));
            GetSchemaIsInCollection(method.Statements, "ds", "xs");
            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable("type")));
            return(method);
        }
Example #21
0
        private CodeMemberMethod GenerateInternal()
        {
            CodeMemberMethod dbMethod = null;

            dbMethod = CodeGenHelper.MethodDecl(CodeGenHelper.Type(base.returnType), base.MethodName, base.methodAttributes);
            dbMethod.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
            this.AddParametersToMethod(dbMethod);
            if (base.declarationOnly)
            {
                return(dbMethod);
            }
            this.AddCustomAttributesToMethod(dbMethod);
            if (this.AddStatementsToMethod(dbMethod))
            {
                return(dbMethod);
            }
            return(null);
        }
        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 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 CodeMemberMethod InitExpressionsMethod()
        {
            bool             flag   = false;
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), "InitExpressions", MemberAttributes.Private);

            foreach (DataColumn column in this.designTable.DataTable.Columns)
            {
                if (column.Expression.Length > 0)
                {
                    CodeExpression exp = CodeGenHelper.Property(CodeGenHelper.This(), this.codeGenerator.TableHandler.Tables[column.Table.TableName].DesignColumns[column.ColumnName].GeneratorColumnPropNameInTable);
                    flag = true;
                    method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(exp, "Expression"), CodeGenHelper.Str(column.Expression)));
                }
            }
            if (flag)
            {
                return(method);
            }
            return(null);
        }
        private void AddFindByMethods(CodeTypeDeclaration dataTableClass)
        {
            DataTable dataTable = this.designTable.DataTable;

            for (int i = 0; i < dataTable.Constraints.Count; i++)
            {
                if ((dataTable.Constraints[i] is UniqueConstraint) && ((UniqueConstraint)dataTable.Constraints[i]).IsPrimaryKey)
                {
                    DataColumn[] columns   = ((UniqueConstraint)dataTable.Constraints[i]).Columns;
                    string       inVarName = "FindBy";
                    bool         flag      = true;
                    for (int j = 0; j < columns.Length; j++)
                    {
                        inVarName = inVarName + this.codeGenerator.TableHandler.Tables[columns[j].Table.TableName].DesignColumns[columns[j].ColumnName].GeneratorColumnPropNameInRow;
                        if (columns[j].ColumnMapping != MappingType.Hidden)
                        {
                            flag = false;
                        }
                    }
                    if (!flag)
                    {
                        CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowClassName), NameHandler.FixIdName(inVarName), MemberAttributes.Public | MemberAttributes.Final);
                        for (int k = 0; k < columns.Length; k++)
                        {
                            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(columns[k].DataType), this.codeGenerator.TableHandler.Tables[columns[k].Table.TableName].DesignColumns[columns[k].ColumnName].GeneratorColumnPropNameInRow));
                        }
                        CodeArrayCreateExpression par = new CodeArrayCreateExpression(typeof(object), columns.Length);
                        for (int m = 0; m < columns.Length; m++)
                        {
                            par.Initializers.Add(CodeGenHelper.Argument(this.codeGenerator.TableHandler.Tables[columns[m].Table.TableName].DesignColumns[columns[m].ColumnName].GeneratorColumnPropNameInRow));
                        }
                        method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(this.rowClassName), CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Find", par))));
                        dataTableClass.Members.Add(method);
                    }
                }
            }
        }
        internal void AddRowGetRelatedRowsMethods(CodeTypeDeclaration rowClass)
        {
            DataRelationCollection childRelations = this.table.ChildRelations;

            for (int i = 0; i < childRelations.Count; i++)
            {
                DataRelation     relation = childRelations[i];
                string           generatorRowClassName = this.codeGenerator.TableHandler.Tables[relation.ChildTable.TableName].GeneratorRowClassName;
                CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.Type(generatorRowClassName, 1), this.codeGenerator.RelationHandler.Relations[relation.RelationName].GeneratorChildPropName, MemberAttributes.Public | MemberAttributes.Final);
                method.Statements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), "Table"), "ChildRelations"), CodeGenHelper.Str(relation.RelationName)), CodeGenHelper.Primitive(null)), CodeGenHelper.Return(new CodeArrayCreateExpression(generatorRowClassName, 0)), CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(generatorRowClassName, 1), CodeGenHelper.MethodCall(CodeGenHelper.Base(), "GetChildRows", CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), "Table"), "ChildRelations"), CodeGenHelper.Str(relation.RelationName)))))));
                rowClass.Members.Add(method);
            }
            DataRelationCollection parentRelations = this.table.ParentRelations;

            for (int j = 0; j < parentRelations.Count; j++)
            {
                DataRelation       relation2 = parentRelations[j];
                string             type      = this.codeGenerator.TableHandler.Tables[relation2.ParentTable.TableName].GeneratorRowClassName;
                CodeMemberProperty property  = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(type), this.codeGenerator.RelationHandler.Relations[relation2.RelationName].GeneratorParentPropName, MemberAttributes.Public | MemberAttributes.Final);
                property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(type), CodeGenHelper.MethodCall(CodeGenHelper.This(), "GetParentRow", CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), "Table"), "ParentRelations"), CodeGenHelper.Str(relation2.RelationName))))));
                property.SetStatements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "SetParentRow", new CodeExpression[] { CodeGenHelper.Value(), CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), "Table"), "ParentRelations"), CodeGenHelper.Str(relation2.RelationName)) }));
                rowClass.Members.Add(property);
            }
        }
        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);
                }
            }
        }
        private void AddTypedRowByColumnsMethods(CodeTypeDeclaration dataTableClass)
        {
            DataTable dataTable = this.designTable.DataTable;
            ArrayList list      = new ArrayList();
            bool      flag      = false;

            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                if (!dataTable.Columns[i].AutoIncrement)
                {
                    list.Add(dataTable.Columns[i]);
                }
            }
            string             name    = NameHandler.FixIdName("Add" + this.rowClassName);
            GenericNameHandler handler = new GenericNameHandler(new string[] { name, columnValuesArrayName }, this.codeGenerator.CodeProvider);
            CodeMemberMethod   method  = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), name, MemberAttributes.Public | MemberAttributes.Final);
            CodeMemberMethod   method2 = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), name, MemberAttributes.Public | MemberAttributes.Final);

            DataColumn[] array = new DataColumn[list.Count];
            list.CopyTo(array, 0);
            for (int j = 0; j < array.Length; j++)
            {
                Type         dataType = array[j].DataType;
                DataRelation relation = this.FindParentRelation(array[j]);
                if (this.ChildRelationFollowable(relation))
                {
                    string generatorRowClassName = this.codeGenerator.TableHandler.Tables[relation.ParentTable.TableName].GeneratorRowClassName;
                    string originalName          = NameHandler.FixIdName("parent" + generatorRowClassName + "By" + relation.RelationName);
                    method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(generatorRowClassName), handler.AddNameToList(originalName)));
                    method2.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(generatorRowClassName), handler.GetNameFromList(originalName)));
                }
                else
                {
                    method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(dataType), handler.AddNameToList(this.codeGenerator.TableHandler.Tables[array[j].Table.TableName].DesignColumns[array[j].ColumnName].GeneratorColumnPropNameInRow)));
                    if (StringUtil.Empty(array[j].Expression))
                    {
                        method2.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(dataType), handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[j].Table.TableName].DesignColumns[array[j].ColumnName].GeneratorColumnPropNameInRow)));
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            CodeStatement statement = CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.rowConcreteClassName), NameHandler.FixIdName("row" + this.rowClassName), CodeGenHelper.Cast(CodeGenHelper.Type(this.rowConcreteClassName), CodeGenHelper.MethodCall(CodeGenHelper.This(), "NewRow")));

            method.Statements.Add(statement);
            method2.Statements.Add(statement);
            CodeExpression      exp        = CodeGenHelper.Variable(NameHandler.FixIdName("row" + this.rowClassName));
            CodeAssignStatement statement2 = new CodeAssignStatement {
                Left = CodeGenHelper.Property(exp, "ItemArray")
            };
            CodeArrayCreateExpression initExpr = new CodeArrayCreateExpression {
                CreateType = CodeGenHelper.GlobalType(typeof(object))
            };
            CodeArrayCreateExpression expression3 = new CodeArrayCreateExpression {
                CreateType = CodeGenHelper.GlobalType(typeof(object))
            };

            array = new DataColumn[dataTable.Columns.Count];
            dataTable.Columns.CopyTo(array, 0);
            for (int k = 0; k < array.Length; k++)
            {
                if (array[k].AutoIncrement)
                {
                    initExpr.Initializers.Add(CodeGenHelper.Primitive(null));
                    expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                }
                else
                {
                    DataRelation relation2 = this.FindParentRelation(array[k]);
                    if (this.ChildRelationFollowable(relation2))
                    {
                        initExpr.Initializers.Add(CodeGenHelper.Primitive(null));
                        expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                    }
                    else
                    {
                        initExpr.Initializers.Add(CodeGenHelper.Argument(handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[k].Table.TableName].DesignColumns[array[k].ColumnName].GeneratorColumnPropNameInRow)));
                        if (StringUtil.Empty(array[k].Expression))
                        {
                            expression3.Initializers.Add(CodeGenHelper.Argument(handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[k].Table.TableName].DesignColumns[array[k].ColumnName].GeneratorColumnPropNameInRow)));
                        }
                        else
                        {
                            expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                        }
                    }
                }
            }
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(object), 1), columnValuesArrayName, initExpr));
            method2.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(object), 1), columnValuesArrayName, expression3));
            for (int m = 0; m < array.Length; m++)
            {
                if (!array[m].AutoIncrement)
                {
                    DataRelation relation3 = this.FindParentRelation(array[m]);
                    if (this.ChildRelationFollowable(relation3))
                    {
                        string        str5       = NameHandler.FixIdName("parent" + this.codeGenerator.TableHandler.Tables[relation3.ParentTable.TableName].GeneratorRowClassName + "By" + relation3.RelationName);
                        CodeStatement statement3 = CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Argument(handler.GetNameFromList(str5)), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Indexer(CodeGenHelper.Variable(columnValuesArrayName), CodeGenHelper.Primitive(m)), CodeGenHelper.Indexer(CodeGenHelper.Argument(handler.GetNameFromList(str5)), CodeGenHelper.Primitive(relation3.ParentColumns[0].Ordinal))));
                        method.Statements.Add(statement3);
                        method2.Statements.Add(statement3);
                    }
                }
            }
            statement2.Right = CodeGenHelper.Variable(columnValuesArrayName);
            method.Statements.Add(statement2);
            method2.Statements.Add(statement2);
            CodeExpression expression4 = CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Add", exp);

            method.Statements.Add(expression4);
            method2.Statements.Add(expression4);
            method.Statements.Add(CodeGenHelper.Return(exp));
            method2.Statements.Add(CodeGenHelper.Return(exp));
            dataTableClass.Members.Add(method);
            if (flag)
            {
                dataTableClass.Members.Add(method2);
            }
        }
        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);
        }
        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);
        }