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 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 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 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 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 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 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 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 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 CodeConstructor ArgumentLessConstructorNoInitExpressions() { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Public | MemberAttributes.Final); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "TableName"), CodeGenHelper.Str(this.designTable.Name))); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "BeginInit")); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitClass")); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "EndInit")); return(constructor); }
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") }); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitVars")); return(constructor); }
internal static void GetSchemaIsInCollection(CodeStatementCollection statements, string dsName, string collectionName) { CodeStatement[] trueStms = new CodeStatement[] { CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Position"), CodeGenHelper.Primitive(0)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Variable("s2"), "Position"), CodeGenHelper.Primitive(0)), CodeGenHelper.ForLoop(CodeGenHelper.Stm(new CodeSnippetExpression("")), CodeGenHelper.And(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Position"), CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Length")), CodeGenHelper.EQ(CodeGenHelper.MethodCall(CodeGenHelper.Variable("s1"), "ReadByte", new CodeExpression[0]), CodeGenHelper.MethodCall(CodeGenHelper.Variable("s2"), "ReadByte", new CodeExpression[0]))), CodeGenHelper.Stm(new CodeSnippetExpression("")), new CodeStatement[] { CodeGenHelper.Stm(new CodeSnippetExpression("")) }), CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Position"), CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Length")), new CodeStatement[] { CodeGenHelper.Return(CodeGenHelper.Variable("type")) }) }; CodeStatement[] statementArray2 = new CodeStatement[] { CodeGenHelper.Assign(CodeGenHelper.Variable("schema"), CodeGenHelper.Cast(CodeGenHelper.GlobalType(typeof(XmlSchema)), CodeGenHelper.Property(CodeGenHelper.Variable("schemas"), "Current"))), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("s2"), "SetLength", new CodeExpression[] { CodeGenHelper.Primitive(0) })), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("schema"), "Write", new CodeExpression[] { CodeGenHelper.Variable("s2") })), CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.Variable("s1"), "Length"), CodeGenHelper.Property(CodeGenHelper.Variable("s2"), "Length")), trueStms) }; CodeStatement[] tryStmnts = new CodeStatement[] { CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchema)), "schema", CodeGenHelper.Primitive(null)), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("dsSchema"), "Write", new CodeExpression[] { CodeGenHelper.Variable("s1") })), CodeGenHelper.ForLoop(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(IEnumerator)), "schemas", CodeGenHelper.MethodCall(CodeGenHelper.MethodCall(CodeGenHelper.Variable(collectionName), "Schemas", new CodeExpression[] { CodeGenHelper.Property(CodeGenHelper.Variable("dsSchema"), "TargetNamespace") }), "GetEnumerator", new CodeExpression[0])), CodeGenHelper.MethodCall(CodeGenHelper.Variable("schemas"), "MoveNext", new CodeExpression[0]), CodeGenHelper.Stm(new CodeSnippetExpression("")), statementArray2) }; CodeStatement[] finallyStmnts = new CodeStatement[] { CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Variable("s1"), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("s1"), "Close", new CodeExpression[0])) }), CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Variable("s2"), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable("s2"), "Close", new CodeExpression[0])) }) }; CodeStatement[] statementArray5 = new CodeStatement[] { CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(MemoryStream)), "s1", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(MemoryStream)), new CodeExpression[0])), CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(MemoryStream)), "s2", CodeGenHelper.New(CodeGenHelper.GlobalType(typeof(MemoryStream)), new CodeExpression[0])), CodeGenHelper.Try(tryStmnts, new CodeCatchClause[0], finallyStmnts) }; statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(XmlSchema)), "dsSchema", CodeGenHelper.MethodCall(CodeGenHelper.Variable(dsName), "GetSchemaSerializable", new CodeExpression[0]))); statements.Add(CodeGenHelper.If(CodeGenHelper.MethodCall(CodeGenHelper.Variable(collectionName), "Contains", new CodeExpression[] { CodeGenHelper.Property(CodeGenHelper.Variable("dsSchema"), "TargetNamespace") }), statementArray5)); statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Argument("xs"), "Add", new CodeExpression[] { CodeGenHelper.Variable("dsSchema") })); }
private CodeConstructor ConstructorWithBoolArgument() { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Assembly | MemberAttributes.Final); constructor.Attributes = MemberAttributes.Public | MemberAttributes.Final; constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(bool)), "initExpressions")); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "TableName"), CodeGenHelper.Str(this.designTable.Name))); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "BeginInit")); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitClass")); constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Argument("initExpressions"), CodeGenHelper.Primitive(true)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitExpressions")) })); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "EndInit")); return(constructor); }
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 CodeConstructor ConstructorWithArguments() { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Assembly | MemberAttributes.Final); constructor.Attributes = MemberAttributes.Assembly | MemberAttributes.Final; constructor.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(DataTable)), "table")); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "TableName"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "TableName"))); constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "CaseSensitive"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "DataSet"), "CaseSensitive")), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "CaseSensitive"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "CaseSensitive")))); constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "Locale"), "ToString"), CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "DataSet"), "Locale"), "ToString")), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Locale"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "Locale")))); constructor.Statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "Namespace"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Argument("table"), "DataSet"), "Namespace")), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Namespace"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "Namespace")))); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "Prefix"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "Prefix"))); constructor.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.This(), "MinimumCapacity"), CodeGenHelper.Property(CodeGenHelper.Argument("table"), "MinimumCapacity"))); return(constructor); }
private bool AddCallOverloadUpdateStm(CodeMemberMethod dbMethod) { int count = 0; if (base.activeCommand.Parameters != null) { count = base.activeCommand.Parameters.Count; } if (count <= 0) { return(false); } List <CodeExpression> list = new List <CodeExpression>(); bool flag = false; for (int i = 0; i < count; i++) { DesignParameter currentVersionParameter = base.activeCommand.Parameters[i]; if (currentVersionParameter == null) { throw new DataSourceGeneratorException("Parameter type is not DesignParameter."); } if (((currentVersionParameter.Direction == ParameterDirection.Input) || (currentVersionParameter.Direction == ParameterDirection.InputOutput)) && !currentVersionParameter.SourceColumnNullMapping) { if ((currentVersionParameter.SourceVersion == DataRowVersion.Current) && this.IsPrimaryColumn(currentVersionParameter.SourceColumn)) { DesignParameter originalVersionParameter = this.GetOriginalVersionParameter(currentVersionParameter); if (originalVersionParameter != null) { flag = true; currentVersionParameter = originalVersionParameter; } } if (currentVersionParameter != null) { string nameFromList = base.nameHandler.GetNameFromList(currentVersionParameter.ParameterName); list.Add(CodeGenHelper.Argument(nameFromList)); } } } if (!flag) { return(false); } CodeStatement statement = CodeGenHelper.Return(CodeGenHelper.MethodCall(CodeGenHelper.This(), "Update", list.ToArray())); dbMethod.Statements.Add(statement); return(true); }
private CodeConstructor PublicConstructor() { CodeConstructor constructor = CodeGenHelper.Constructor(MemberAttributes.Public); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "BeginInit")); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitClass")); 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.Base(), "Relations"), "CollectionChanged"), CodeGenHelper.Variable("schemaChangedHandler"))); constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "EndInit")); if (this.initExpressionsMethod != null) { constructor.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.This(), "InitExpressions")); } return(constructor); }
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); }
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 AddCommandInitStatements(IList statements, CodeExpression commandExpression, DbSourceCommand command, DbProviderFactory currentFactory, bool isFunctionsDataComponent) { if (((statements == null) || (commandExpression == null)) || (command == null)) { throw new InternalException("Argument should not be null."); } Type parameterType = currentFactory.CreateParameter().GetType(); Type type = currentFactory.CreateCommand().GetType(); CodeExpression parameterVariable = null; statements.Add(CodeGenHelper.Assign(commandExpression, CodeGenHelper.New(CodeGenHelper.GlobalType(type), new CodeExpression[0]))); if (isFunctionsDataComponent) { commandExpression = CodeGenHelper.Cast(CodeGenHelper.GlobalType(type), commandExpression); } if ((((DbSource)command.Parent).Connection == null) || ((this.designTable.Connection != null) && (this.designTable.Connection == ((DbSource)command.Parent).Connection))) { statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionPropertyName))); } else { Type type3 = currentFactory.CreateConnection().GetType(); IDesignConnection connection = ((DbSource)command.Parent).Connection; CodeExpression propertyReference = null; if (connection.PropertyReference == null) { propertyReference = CodeGenHelper.Str(connection.ConnectionStringObject.ToFullString()); } else { propertyReference = connection.PropertyReference; } statements.Add(CodeGenHelper.Assign(CodeGenHelper.Property(commandExpression, "Connection"), CodeGenHelper.New(CodeGenHelper.GlobalType(type3), new CodeExpression[] { propertyReference }))); } statements.Add(QueryGeneratorBase.SetCommandTextStatement(commandExpression, command.CommandText)); statements.Add(QueryGeneratorBase.SetCommandTypeStatement(commandExpression, command.CommandType)); if (command.Parameters != null) { foreach (DesignParameter parameter in command.Parameters) { parameterVariable = QueryGeneratorBase.AddNewParameterStatements(parameter, parameterType, currentFactory, statements, parameterVariable); statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(commandExpression, "Parameters"), "Add", new CodeExpression[] { parameterVariable }))); } } }
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 bool AddClearStatements(IList statements) { if (!base.getMethod) { CodeStatement trueStm = null; if (base.containerParamType == typeof(DataTable)) { trueStm = CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Argument(base.ContainerParameterName), "Clear", new CodeExpression[0])); } else { if (base.containerParamType != typeof(DataSet)) { throw new InternalException("Unknown containerParameterType."); } trueStm = CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Argument(base.ContainerParameterName), base.DesignTable.GeneratorTablePropName), "Clear", new CodeExpression[0])); } statements.Add(CodeGenHelper.If(CodeGenHelper.EQ(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.ClearBeforeFillPropertyName), CodeGenHelper.Primitive(true)), trueStm)); } return(true); }
private bool AddExecuteCommandStatements(IList statements) { if (base.getMethod) { CodeExpression[] expressionArray = new CodeExpression[0]; if ((base.designTable != null) && base.designTable.HasAnyExpressionColumn) { expressionArray = new CodeExpression[] { CodeGenHelper.Primitive(true) }; } statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(base.ContainerParameterTypeName), base.ContainerParameterName, CodeGenHelper.New(CodeGenHelper.Type(base.ContainerParameterTypeName), expressionArray))); } CodeExpression[] parameters = new CodeExpression[] { CodeGenHelper.Variable(base.ContainerParameterName) }; if (!base.getMethod) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName, CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } else { statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } return(true); }
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); } }
private bool AddExecuteCommandStatementsForPaging(IList statements) { if (base.containerParamType == typeof(DataTable)) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(base.codeGenerator.DataSourceName), base.nameHandler.AddNameToList("dataSet"), CodeGenHelper.New(CodeGenHelper.Type(base.codeGenerator.DataSourceName), new CodeExpression[0]))); } CodeExpression[] parameters = new CodeExpression[4]; if (base.containerParamType == typeof(DataTable)) { parameters[0] = CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")); } else { parameters[0] = CodeGenHelper.Argument(base.ContainerParameterName); } parameters[1] = CodeGenHelper.Argument(base.nameHandler.GetNameFromList(QueryGeneratorBase.startRecordParameterName)); parameters[2] = CodeGenHelper.Argument(base.nameHandler.GetNameFromList(QueryGeneratorBase.maxRecordsParameterName)); parameters[3] = CodeGenHelper.Str("Table"); if (!base.getMethod) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName, CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } else { statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } if ((base.containerParamType == typeof(DataTable)) && !base.getMethod) { CodeStatement initStmt = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), "i", CodeGenHelper.Primitive(0)); CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")), base.DesignTable.GeneratorName), "Rows"), "Count")); CodeStatement incrementStmt = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1))); CodeStatement statement3 = CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Argument(base.ContainerParameterName), "ImportRow", new CodeExpression[] { CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")), base.DesignTable.GeneratorName), "Rows"), CodeGenHelper.Variable("i")) })); statements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 })); } return(true); }
private static void GenerateProperties(CodeExpression addTarget, IList statementCollection, ICollection extendedProperties) { if (extendedProperties != null) { IDictionaryEnumerator enumerator = (IDictionaryEnumerator)extendedProperties.GetEnumerator(); if (enumerator != null) { enumerator.Reset(); while (enumerator.MoveNext()) { string key = enumerator.Key as string; string primitive = enumerator.Value as string; if ((key == null) || (primitive == null)) { codeGenerator.ProblemList.Add(new DSGeneratorProblem(System.Design.SR.GetString("CG_UnableToReadExtProperties"), ProblemSeverity.NonFatalError, targetObject)); } else { statementCollection.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(addTarget, "ExtendedProperties"), "Add", new CodeExpression[] { CodeGenHelper.Primitive(key), CodeGenHelper.Primitive(primitive) }))); } } } } }
private bool AddExecuteCommandStatements(IList statements) { 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.Variable(QueryGeneratorBase.commandVariableName), "Connection"), "State"))); statements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.BitwiseAnd(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "Connection"), "State"), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(ConnectionState)), "Open")), CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "Connection"), "Open")))); if (base.methodSource.QueryType == QueryType.Scalar) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(object)), QueryGeneratorBase.returnVariableName)); tryStmnts[0] = CodeGenHelper.Assign(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName), CodeGenHelper.MethodCall(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "ExecuteScalar", new CodeExpression[0])); } else if ((base.methodSource.DbObjectType == DbObjectType.Function) && (base.GetReturnParameterPosition(base.activeCommand) >= 0)) { tryStmnts[0] = CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "ExecuteNonQuery", new CodeExpression[0])); } else { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName)); tryStmnts[0] = CodeGenHelper.Assign(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName), CodeGenHelper.MethodCall(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "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.Variable(QueryGeneratorBase.commandVariableName), "Connection"), "Close"))); statements.Add(CodeGenHelper.Try(tryStmnts, new CodeCatchClause[0], finallyStmnts)); return(true); }
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); }
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); } } }