コード例 #1
0
        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);
        }