private void AddTransactionMembers(CodeTypeDeclaration dataComponentClass) { Type transactionType = this.designTable.PropertyCache.TransactionType; if (transactionType != null) { CodeTypeReference type = CodeGenHelper.GlobalType(transactionType); dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(type, DataComponentNameHandler.TransactionVariableName)); CodeMemberProperty property = CodeGenHelper.PropertyDecl(type, DataComponentNameHandler.TransactionPropertyName, MemberAttributes.Assembly | MemberAttributes.Final); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName))); property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName), CodeGenHelper.Argument("value"))); CodeStatement initStmt = CodeGenHelper.VariableDecl(CodeGenHelper.Type(typeof(int)), "i", CodeGenHelper.Primitive(0)); CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), "Length")); CodeStatement incrementStmt = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1))); CodeExpression transaction = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i")), "Transaction"); CodeExpression oldTransaction = CodeGenHelper.Variable("oldTransaction"); CodeExpression newTransaction = CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName); CodeStatement statement3 = this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction); property.SetStatements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 })); CodeExpression exp = CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName); CodeExpression expression6 = CodeGenHelper.Property(exp, "DeleteCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); expression6 = CodeGenHelper.Property(exp, "InsertCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); expression6 = CodeGenHelper.Property(exp, "UpdateCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); dataComponentClass.Members.Add(property); } }
private CodeConstructor ArgumentLessConstructorInitExpressions() { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Public | MemberAttributes.Final); constructor.ChainedConstructorArgs.Add(CodeGenHelper.Primitive(false)); return(constructor); }
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 void AddConstructor(CodeTypeDeclaration dataComponentClass) { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Public); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.ClearBeforeFillPropertyName), CodeGenHelper.Primitive(true))); dataComponentClass.Members.Add(constructor); }
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 void AddParametersToMethod(CodeMemberMethod dbMethod) { CodeParameterDeclarationExpression expression = null; if (base.activeCommand.Parameters != null) { DesignConnection connection = (DesignConnection)base.methodSource.Connection; if (connection == null) { throw new InternalException("Connection for query '" + base.methodSource.Name + "' is null."); } string parameterPrefix = connection.ParameterPrefix; foreach (DesignParameter parameter in base.activeCommand.Parameters) { if (parameter.Direction != ParameterDirection.ReturnValue) { Type parameterUrtType = base.GetParameterUrtType(parameter); string name = base.nameHandler.AddParameterNameToList(parameter.ParameterName, parameterPrefix); CodeTypeReference type = null; if (parameter.AllowDbNull && parameterUrtType.IsValueType) { type = CodeGenHelper.NullableType(parameterUrtType); } else { type = CodeGenHelper.Type(parameterUrtType); } expression = CodeGenHelper.ParameterDecl(type, name); expression.Direction = CodeGenHelper.ParameterDirectionToFieldDirection(parameter.Direction); dbMethod.Parameters.Add(expression); } } } }
private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod) { if (base.methodSource.EnableWebMethods) { CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod"); declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription))); dbMethod.CustomAttributes.Add(declaration); } DataObjectMethodType select = DataObjectMethodType.Select; if (base.methodSource.CommandOperation == CommandOperation.Update) { select = DataObjectMethodType.Update; } else if (base.methodSource.CommandOperation == CommandOperation.Delete) { select = DataObjectMethodType.Delete; } else if (base.methodSource.CommandOperation == CommandOperation.Insert) { select = DataObjectMethodType.Insert; } if (select != DataObjectMethodType.Select) { dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), select.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(false)) })); } }
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 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); }
protected bool AddSetReturnParamValuesStatements(IList statements) { CodeExpression commandExpression = CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName); CodeTryCatchFinallyStatement statement = (CodeTryCatchFinallyStatement)statements[statements.Count - 1]; return(base.AddSetReturnParamValuesStatements(statement.TryStatements, commandExpression)); }
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 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); }
private bool AddExecuteCommandStatements(IList statements) { if (base.MethodType == MethodTypeEnum.ColumnParameters) { CodeStatement[] tryStmnts = new CodeStatement[1]; CodeStatement[] finallyStmnts = new CodeStatement[1]; statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(ConnectionState)), base.nameHandler.AddNameToList("previousConnectionState"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "State"))); statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.BitwiseAnd(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "State"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "Open")))); tryStmnts[0] = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName, CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "ExecuteNonQuery", new CodeExpression[0])); finallyStmnts[0] = CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("previousConnectionState")), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Closed")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName), "Connection"), "Close"))); statements.Add(CodeGenHelper.Try(tryStmnts, new CodeCatchClause[0], finallyStmnts)); } else if (StringUtil.EqualValue(base.UpdateParameterTypeReference.BaseType, typeof(DataRow).FullName) && (base.UpdateParameterTypeReference.ArrayRank == 0)) { statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.NewArray(base.UpdateParameterTypeReference, new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName) }) }))); } else if (StringUtil.EqualValue(base.UpdateParameterTypeReference.BaseType, typeof(DataSet).FullName)) { statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName), CodeGenHelper.Str(base.DesignTable.Name) }))); } else { statements.Add(CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Update", new CodeExpression[] { CodeGenHelper.Argument(base.UpdateParameterName) }))); } return(true); }
private bool AddSetParametersStatements(IList statements) { int count = 0; if (base.activeCommand.Parameters != null) { count = base.activeCommand.Parameters.Count; } for (int i = 0; i < count; i++) { DesignParameter originalParameter = base.activeCommand.Parameters[i]; if (originalParameter == null) { throw new DataSourceGeneratorException("Parameter type is not DesignParameter."); } if (((originalParameter.Direction == ParameterDirection.Input) || (originalParameter.Direction == ParameterDirection.InputOutput)) && !originalParameter.SourceColumnNullMapping) { string nameFromList = base.nameHandler.GetNameFromList(originalParameter.ParameterName); CodeExpression cmdExpression = CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), base.UpdateCommandName); DesignParameter isNullParameter = null; int isNullParameterIndex = 0; if (originalParameter.SourceVersion == DataRowVersion.Original) { isNullParameter = this.FindCorrespondingIsNullParameter(originalParameter, out isNullParameterIndex); } base.AddSetParameterStatements(originalParameter, nameFromList, isNullParameter, cmdExpression, i, isNullParameterIndex, statements); } } return(true); }
private void GenerateQueries(CodeTypeDeclaration classDeclaration, QueryGenerator queryGenerator) { CodeMemberMethod method = null; if (queryGenerator.DeclarationOnly) { if (!queryGenerator.GenerateGetMethod && (queryGenerator.MethodSource.Modifier != MemberAttributes.Public)) { return; } if (queryGenerator.GenerateGetMethod && (queryGenerator.MethodSource.GetMethodModifier != MemberAttributes.Public)) { return; } } queryGenerator.ContainerParameterType = typeof(DataTable); queryGenerator.ContainerParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSourceName, this.designTable.GeneratorTableClassName); if (this.codeGenerator.DataSetNamespace != null) { queryGenerator.ContainerParameterTypeName = CodeGenHelper.GetTypeName(this.codeGenerator.CodeProvider, this.codeGenerator.DataSetNamespace, queryGenerator.ContainerParameterTypeName); } queryGenerator.ContainerParameterName = "dataTable"; queryGenerator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects; method = queryGenerator.Generate(); if (method != null) { classDeclaration.Members.Add(method); } }
private bool AddReturnStatements(IList statements) { CodeTryCatchFinallyStatement statement = (CodeTryCatchFinallyStatement)statements[statements.Count - 1]; statement.TryStatements.Add(CodeGenHelper.Return(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName))); return(true); }
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); }
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 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 void AddCustomAttributesToMethod(CodeMemberMethod dbMethod) { bool primitive = false; DataObjectMethodType fill = DataObjectMethodType.Fill; if (base.methodSource.EnableWebMethods && base.getMethod) { CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod"); declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription))); dbMethod.CustomAttributes.Add(declaration); } if (!base.GeneratePagingMethod && (base.getMethod || (base.ContainerParameterType == typeof(DataTable)))) { if (base.MethodSource == base.DesignTable.MainSource) { primitive = true; } if (base.getMethod) { fill = DataObjectMethodType.Select; } else { fill = DataObjectMethodType.Fill; } dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), fill.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(primitive)) })); } }
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 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 CodeTypeDeclaration CreateTypedRowEventArg(DesignTable designTable) { if (designTable == null) { throw new InternalException("DesignTable should not be null."); } DataTable dataTable = designTable.DataTable; string generatorRowClassName = designTable.GeneratorRowClassName; string generatorTableClassName = designTable.GeneratorTableClassName; string type = designTable.GeneratorRowClassName; CodeTypeDeclaration declaration = CodeGenHelper.Class(designTable.GeneratorRowEvArgName, false, TypeAttributes.Public); declaration.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(EventArgs))); declaration.Comments.Add(CodeGenHelper.Comment("Row event argument class", true)); declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.Type(type), "eventRow")); declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "eventAction")); declaration.Members.Add(this.EventArgConstructor(type)); CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(type), "Row", MemberAttributes.Public | MemberAttributes.Final); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventRow"))); declaration.Members.Add(property); property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "Action", MemberAttributes.Public | MemberAttributes.Final); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventAction"))); declaration.Members.Add(property); return(declaration); }
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 void AddCustomAttributesToMethod(CodeMemberMethod dbMethod) { DataObjectMethodType update = DataObjectMethodType.Update; if (base.methodSource.EnableWebMethods) { CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod"); declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription))); dbMethod.CustomAttributes.Add(declaration); } if (base.MethodType != MethodTypeEnum.GenericUpdate) { if (base.activeCommand == base.methodSource.DeleteCommand) { update = DataObjectMethodType.Delete; } else if (base.activeCommand == base.methodSource.InsertCommand) { update = DataObjectMethodType.Insert; } else if (base.activeCommand == base.methodSource.UpdateCommand) { update = DataObjectMethodType.Update; } dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), update.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(true)) })); } }
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 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 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 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 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); }