示例#1
0
        private CodeTypeDeclaration GenerateTable(DesignTable designTable, CodeTypeDeclaration dataSourceClass)
        {
            string              generatorTableClassName = designTable.GeneratorTableClassName;
            TypedColumnHandler  columnHandler           = this.codeGenerator.TableHandler.GetColumnHandler(designTable.Name);
            CodeTypeDeclaration dataTableClass          = CodeGenHelper.Class(generatorTableClassName, true, TypeAttributes.Public);

            if ((this.codeGenerator.GenerateOptions & System.Data.Design.TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets) == System.Data.Design.TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets)
            {
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalGenericType(LINQOverTDSTableBaseClass, CodeGenHelper.Type(designTable.GeneratorRowClassName)));
            }
            else
            {
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataTable)));
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(IEnumerable)));
            }
            dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable"));
            dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedTableSchema")));
            dataTableClass.Comments.Add(CodeGenHelper.Comment("Represents the strongly named DataTable class.", true));
            columnHandler.AddPrivateVariables(dataTableClass);
            columnHandler.AddTableColumnProperties(dataTableClass);
            dataTableClass.Members.Add(this.CountProperty());
            if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareIndexerProperties))
            {
                dataTableClass.Members.Add(this.IndexProperty(designTable));
            }
            if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareEvents) && this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareDelegates))
            {
                this.codeGenerator.RowHandler.AddTypedRowEvents(dataTableClass, designTable.Name);
            }
            new TableMethodGenerator(this.codeGenerator, designTable).AddMethods(dataTableClass);
            return(dataTableClass);
        }
        private CodeTypeDeclaration GenerateRow(DesignTable table)
        {
            if (table == null)
            {
                throw new InternalException("DesignTable should not be null.");
            }
            string              generatorRowClassName   = table.GeneratorRowClassName;
            string              generatorTableClassName = table.GeneratorTableClassName;
            string              generatorTableVarName   = table.GeneratorTableVarName;
            TypedColumnHandler  columnHandler           = this.codeGenerator.TableHandler.GetColumnHandler(table.Name);
            CodeTypeDeclaration rowClass = CodeGenHelper.Class(generatorRowClassName, true, TypeAttributes.Public);

            rowClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataRow)));
            rowClass.Comments.Add(CodeGenHelper.Comment("Represents strongly named DataRow class.", true));
            rowClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.Type(generatorTableClassName), generatorTableVarName));
            rowClass.Members.Add(this.RowConstructor(generatorTableClassName, generatorTableVarName));
            columnHandler.AddRowColumnProperties(rowClass);
            columnHandler.AddRowGetRelatedRowsMethods(rowClass);
            return(rowClass);
        }