private CodeTypeDeclaration CreateDataSourceDeclaration(DesignDataSource dtDataSource) { if (dtDataSource.Name == null) { throw new DataSourceGeneratorException("DataSource name cannot be null."); } new NameHandler(this.codeProvider).GenerateMemberNames(dtDataSource, this.problemList); CodeTypeDeclaration dataSourceClass = CodeGenHelper.Class(dtDataSource.GeneratorDataSetName, true, dtDataSource.Modifier); dataSourceClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataSet))); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable")); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code"))); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true))); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedDataSetSchema"))); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlRootAttribute).FullName, CodeGenHelper.Primitive(dtDataSource.GeneratorDataSetName))); dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.DataSet"))); dataSourceClass.Comments.Add(CodeGenHelper.Comment("Represents a strongly typed in-memory cache of data.", true)); this.tableHandler = new TypedTableHandler(this, dtDataSource.DesignTables); this.relationHandler = new System.Data.Design.RelationHandler(this, dtDataSource.DesignRelations); this.rowHandler = new TypedRowHandler(this, dtDataSource.DesignTables); DatasetMethodGenerator generator = new DatasetMethodGenerator(this, dtDataSource); this.tableHandler.AddPrivateVars(dataSourceClass); this.tableHandler.AddTableProperties(dataSourceClass); this.relationHandler.AddPrivateVars(dataSourceClass); generator.AddMethods(dataSourceClass); this.rowHandler.AddTypedRowEventHandlers(dataSourceClass); this.tableHandler.AddTableClasses(dataSourceClass); this.rowHandler.AddTypedRows(dataSourceClass); this.rowHandler.AddTypedRowEventArgs(dataSourceClass); return(dataSourceClass); }
internal CodeTypeDeclaration GenerateAdapterManager(DesignDataSource dataSource, CodeTypeDeclaration dataSourceClass) { TypeAttributes @public = TypeAttributes.Public; foreach (DesignTable table in dataSource.DesignTables) { if ((table.DataAccessorModifier & TypeAttributes.Public) != TypeAttributes.Public) { @public = table.DataAccessorModifier; } } CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class("TableAdapterManager", true, @public); dataComponentClass.Comments.Add(CodeGenHelper.Comment("TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios", true)); dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(Component))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code"))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str("Microsoft.VSDesigner.DataSource.Design.TableAdapterManagerDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapterManager"))); new TableAdapterManagerMethodGenerator(this.dataSourceGenerator, dataSource, dataSourceClass).AddEverything(dataComponentClass); try { CodeGenerator.ValidateIdentifiers(dataComponentClass); } catch (Exception) { } return(dataComponentClass); }
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); }
internal CodeTypeDeclaration GenerateDataComponent(DesignTable designTable, bool isFunctionsComponent, bool generateHierarchicalUpdate) { CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class(designTable.GeneratorDataComponentClassName, true, designTable.DataAccessorModifier); dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(designTable.BaseClass)); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code"))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DataObjectAttribute", CodeGenHelper.Primitive(true))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str(adapterDesigner + ", Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"))); dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter"))); if (designTable.WebServiceAttribute) { CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration("System.Web.Services.WebService"); declaration2.Arguments.Add(new CodeAttributeArgument("Namespace", CodeGenHelper.Str(designTable.WebServiceNamespace))); declaration2.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(designTable.WebServiceDescription))); dataComponentClass.CustomAttributes.Add(declaration2); } dataComponentClass.Comments.Add(CodeGenHelper.Comment("Represents the connection and commands used to retrieve and save data.", true)); new DataComponentMethodGenerator(this.dataSourceGenerator, designTable, generateHierarchicalUpdate).AddMethods(dataComponentClass, isFunctionsComponent); CodeGenerator.ValidateIdentifiers(dataComponentClass); QueryHandler handler = new QueryHandler(this.dataSourceGenerator, designTable); if (isFunctionsComponent) { handler.AddFunctionsToDataComponent(dataComponentClass, true); return(dataComponentClass); } handler.AddQueriesToDataComponent(dataComponentClass); return(dataComponentClass); }
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 CodeMemberProperty TablesProperty() { CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataTableCollection)), DataSourceNameHandler.TablesPropertyName, MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Final); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerSerializationVisibilityAttribute", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Hidden"))); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Property(CodeGenHelper.Base(), "Tables"))); return(property); }
private CodeMemberProperty CountProperty() { CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(int)), "Count", MemberAttributes.Public | MemberAttributes.Final); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.Browsable", CodeGenHelper.Primitive(false))); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Count"))); return(property); }
private void AddSchemaSerializationModeMembers(CodeTypeDeclaration dataSourceClass) { CodeMemberField field = CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(SchemaSerializationMode)), "_schemaSerializationMode", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(SchemaSerializationMode)), this.dataSource.SchemaSerializationMode.ToString())); dataSourceClass.Members.Add(field); CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(SchemaSerializationMode)), "SchemaSerializationMode", MemberAttributes.Public | MemberAttributes.Override); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(BrowsableAttribute).FullName, CodeGenHelper.Primitive(true))); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(DesignerSerializationVisibilityAttribute).FullName, CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Visible"))); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "_schemaSerializationMode"))); property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), "_schemaSerializationMode"), CodeGenHelper.Argument("value"))); dataSourceClass.Members.Add(property); }
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); }
internal void AddTableProperties(CodeTypeDeclaration dataSourceClass) { if (this.tables != null) { foreach (DesignTable table in this.tables) { string generatorTableClassName = table.GeneratorTableClassName; string generatorTablePropName = table.GeneratorTablePropName; string generatorTableVarName = table.GeneratorTableVarName; CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(generatorTableClassName), generatorTablePropName, MemberAttributes.Public | MemberAttributes.Final); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.Browsable", CodeGenHelper.Primitive(false))); property.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerSerializationVisibility", CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DesignerSerializationVisibility)), "Content"))); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), generatorTableVarName))); dataSourceClass.Members.Add(property); } } }
private 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); }