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 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);
        }
        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);
        }