Example #1
0
        public Expression SubStringMethod(SubStringMethod method, LiteralExpression[] arguments)
        {
            if (arguments[0].LiteralType == LiteralType.Null)
            {
                return(arguments[0]);
            }
            else
            {
                int    startIndex;
                int    length;
                string result;

                if (!LiteralUtil.TryCoerceInt(arguments[1], out startIndex))
                {
                    throw new ODataException(String.Format(
                                                 ErrorMessages.Method_InvalidArgumentType,
                                                 method.MethodType, 2, "Edm.Int32"
                                                 ));
                }

                if (arguments.Length == 3)
                {
                    if (!LiteralUtil.TryCoerceInt(arguments[2], out length))
                    {
                        throw new ODataException(String.Format(
                                                     ErrorMessages.Method_InvalidArgumentType,
                                                     method.MethodType, 3, "Edm.Int32"
                                                     ));
                    }

                    result = LiteralUtil.CoerceString(arguments[0]).Substring(startIndex - 1, length);
                }
                else
                {
                    result = LiteralUtil.CoerceString(arguments[0]).Substring(startIndex - 1);
                }

                return(new LiteralExpression(result, LiteralType.String));
            }
        }
Example #2
0
 public override IProjection SubStringMethod(SubStringMethod method, Expression[] arguments)
 {
     if (arguments.Length == 2)
     {
         return(new SqlFunctionProjection(
                    "substring",
                    NHibernateUtil.String,
                    ProjectionVisitor.CreateProjection(arguments[0]),
                    ProjectionVisitor.CreateProjection(arguments[1])
                    ));
     }
     else
     {
         return(new SqlFunctionProjection(
                    "substring",
                    NHibernateUtil.String,
                    ProjectionVisitor.CreateProjection(arguments[0]),
                    ProjectionVisitor.CreateProjection(arguments[1]),
                    ProjectionVisitor.CreateProjection(arguments[2])
                    ));
     }
 }
 public virtual TResult SubStringMethod(SubStringMethod method, Expression[] arguments)
 {
     throw new QueryNotSupportException();
 }