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 AddParametersToMethod(CodeMemberMethod dbMethod) { DesignConnection connection = (DesignConnection)base.methodSource.Connection; if (connection == null) { throw new InternalException(string.Format(CultureInfo.CurrentCulture, "Connection for query {0} is null.", new object[] { base.methodSource.Name })); } string parameterPrefix = connection.ParameterPrefix; if (base.MethodType == MethodTypeEnum.ColumnParameters) { if (base.activeCommand.Parameters != null) { CodeParameterDeclarationExpression expression = null; foreach (DesignParameter parameter in base.activeCommand.Parameters) { if (((parameter.Direction != ParameterDirection.ReturnValue) && !parameter.SourceColumnNullMapping) && ((!this.GenerateOverloadWithoutCurrentPKParameters || (parameter.SourceVersion != DataRowVersion.Current)) || (!this.IsPrimaryColumn(parameter.SourceColumn) || (this.GetOriginalVersionParameter(parameter) == null)))) { 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); } } } } else { CodeParameterDeclarationExpression expression2 = null; string str3 = base.nameHandler.AddParameterNameToList(base.UpdateParameterName, parameterPrefix); if (base.UpdateParameterTypeName != null) { expression2 = CodeGenHelper.ParameterDecl(CodeGenHelper.Type(base.UpdateParameterTypeName), str3); } else { expression2 = CodeGenHelper.ParameterDecl(base.UpdateParameterTypeReference, str3); } dbMethod.Parameters.Add(expression2); } }
private CodeMemberMethod GenerateInternal() { DesignParameter returnParameter = base.GetReturnParameter(base.activeCommand); CodeTypeReference type = null; if (base.methodSource.QueryType == QueryType.Scalar) { base.returnType = base.methodSource.ScalarCallRetval; if (base.returnType.IsValueType) { type = CodeGenHelper.NullableType(base.returnType); } else { type = CodeGenHelper.Type(base.returnType); } } else if ((base.methodSource.DbObjectType == DbObjectType.Function) && (returnParameter != null)) { base.returnType = base.GetParameterUrtType(returnParameter); if (returnParameter.AllowDbNull && base.returnType.IsValueType) { type = CodeGenHelper.NullableType(base.returnType); } else { type = CodeGenHelper.Type(base.returnType); } } else { base.returnType = typeof(int); type = CodeGenHelper.Type(base.returnType); } CodeMemberMethod dbMethod = null; dbMethod = CodeGenHelper.MethodDecl(type, base.MethodName, base.methodAttributes); dbMethod.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter"))); this.AddParametersToMethod(dbMethod); if (base.declarationOnly) { base.AddThrowsClauseIfNeeded(dbMethod); return(dbMethod); } this.AddCustomAttributesToMethod(dbMethod); if (this.AddStatementsToMethod(dbMethod)) { return(dbMethod); } return(null); }
private void AddParametersToMethod(CodeMemberMethod dbMethod) { CodeParameterDeclarationExpression expression = null; if (!base.getMethod) { string name = base.nameHandler.AddNameToList(base.ContainerParameterName); expression = CodeGenHelper.ParameterDecl(CodeGenHelper.Type(base.ContainerParameterTypeName), name); dbMethod.Parameters.Add(expression); } if (base.GeneratePagingMethod) { string str2 = base.nameHandler.AddNameToList(QueryGeneratorBase.startRecordParameterName); expression = CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(int)), str2); dbMethod.Parameters.Add(expression); string str3 = base.nameHandler.AddNameToList(QueryGeneratorBase.maxRecordsParameterName); expression = CodeGenHelper.ParameterDecl(CodeGenHelper.GlobalType(typeof(int)), str3); dbMethod.Parameters.Add(expression); } if (base.activeCommand.Parameters != null) { DesignConnection connection = (DesignConnection)base.methodSource.Connection; if (connection == null) { throw new InternalException(string.Format(CultureInfo.CurrentCulture, "Connection for query {0} is null.", new object[] { base.methodSource.Name })); } string parameterPrefix = connection.ParameterPrefix; foreach (DesignParameter parameter in base.activeCommand.Parameters) { if (parameter.Direction != ParameterDirection.ReturnValue) { Type parameterUrtType = base.GetParameterUrtType(parameter); string str5 = 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, str5); expression.Direction = CodeGenHelper.ParameterDirectionToFieldDirection(parameter.Direction); dbMethod.Parameters.Add(expression); } } } }
protected bool AddSetReturnParamValuesStatements(IList statements, CodeExpression commandExpression) { int count = 0; if (this.activeCommand.Parameters != null) { count = this.activeCommand.Parameters.Count; } for (int i = 0; i < count; i++) { DesignParameter parameter = this.activeCommand.Parameters[i]; if (parameter == null) { throw new DataSourceGeneratorException("Parameter type is not DesignParameter."); } if ((parameter.Direction == ParameterDirection.Output) || (parameter.Direction == ParameterDirection.InputOutput)) { Type parameterUrtType = this.GetParameterUrtType(parameter); string nameFromList = this.nameHandler.GetNameFromList(parameter.ParameterName); CodeExpression returnParam = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(commandExpression, "Parameters"), CodeGenHelper.Primitive(i)), "Value"); CodeExpression cond = CodeGenHelper.GenerateDbNullCheck(returnParam); CodeExpression right = CodeGenHelper.GenerateNullExpression(parameterUrtType); CodeStatement trueStm = null; if (right == null) { if (parameter.AllowDbNull && parameterUrtType.IsValueType) { trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[0])); } else if (parameter.AllowDbNull && !parameterUrtType.IsValueType) { trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.Primitive(null)); } else { trueStm = CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(StrongTypingException)), System.Design.SR.GetString("CG_ParameterIsDBNull", new object[] { nameFromList }), CodeGenHelper.Primitive(null)); } } else { trueStm = CodeGenHelper.Assign(CodeGenHelper.Argument(this.nameHandler.GetNameFromList(parameter.ParameterName)), right); } CodeStatement falseStm = null; if (parameter.AllowDbNull && parameterUrtType.IsValueType) { falseStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam) })); } else { falseStm = CodeGenHelper.Assign(CodeGenHelper.Argument(nameFromList), CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam)); } statements.Add(CodeGenHelper.If(cond, trueStm, falseStm)); } } return(true); }
private bool AddReturnStatements(IList statements) { int returnParameterPosition = base.GetReturnParameterPosition(base.activeCommand); if (((base.methodSource.DbObjectType == DbObjectType.Function) && (base.methodSource.QueryType != QueryType.Scalar)) && (returnParameterPosition >= 0)) { DesignParameter parameter = base.activeCommand.Parameters[returnParameterPosition]; Type parameterUrtType = base.GetParameterUrtType(parameter); CodeExpression returnParam = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Variable(QueryGeneratorBase.commandVariableName), "Parameters"), CodeGenHelper.Primitive(returnParameterPosition)), "Value"); CodeExpression cond = CodeGenHelper.GenerateDbNullCheck(returnParam); CodeExpression expr = CodeGenHelper.GenerateNullExpression(parameterUrtType); CodeStatement trueStm = null; if (expr == null) { if (parameter.AllowDbNull && parameterUrtType.IsValueType) { trueStm = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[0])); } else if (parameter.AllowDbNull && !parameterUrtType.IsValueType) { trueStm = CodeGenHelper.Return(CodeGenHelper.Primitive(null)); } else { trueStm = CodeGenHelper.Throw(CodeGenHelper.GlobalType(typeof(StrongTypingException)), System.Design.SR.GetString("CG_ParameterIsDBNull", new object[] { base.activeCommand.Parameters[returnParameterPosition].ParameterName }), CodeGenHelper.Primitive(null)); } } else { trueStm = CodeGenHelper.Return(expr); } CodeStatement falseStm = null; if (parameter.AllowDbNull && parameterUrtType.IsValueType) { falseStm = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(parameterUrtType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(parameterUrtType), returnParam) })); } else { falseStm = CodeGenHelper.Return(CodeGenHelper.GenerateConvertExpression(returnParam, typeof(object), parameterUrtType)); } statements.Add(CodeGenHelper.If(cond, trueStm, falseStm)); } else if (base.methodSource.QueryType == QueryType.Scalar) { CodeExpression expression5 = CodeGenHelper.GenerateDbNullCheck(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName)); CodeStatement statement3 = null; CodeStatement statement4 = null; if (base.returnType.IsValueType) { statement3 = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(base.returnType), new CodeExpression[0])); statement4 = CodeGenHelper.Return(CodeGenHelper.New(CodeGenHelper.NullableType(base.returnType), new CodeExpression[] { CodeGenHelper.Cast(CodeGenHelper.GlobalType(base.returnType), CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName)) })); } else { statement3 = CodeGenHelper.Return(CodeGenHelper.Primitive(null)); statement4 = CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.GlobalType(base.returnType), CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName))); } statements.Add(CodeGenHelper.If(expression5, statement3, statement4)); } else { statements.Add(CodeGenHelper.Return(CodeGenHelper.Variable(QueryGeneratorBase.returnVariableName))); } return(true); }