public static object GetValue <T>(ParameterExpression parameter, ExpressionValue expressionValue,
                                          QueryParser.ComparisonContext context,
                                          NamingStrategy namingStrategy = null)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }
            if (expressionValue == null)
            {
                throw new ArgumentNullException(nameof(expressionValue));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (expressionValue.Property.PropertyType == typeof(string))
            {
                return(GetString <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(short) ||
                expressionValue.Property.PropertyType == typeof(short?))
            {
                return(GetShort <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(int) ||
                expressionValue.Property.PropertyType == typeof(int?))
            {
                return(GetInt <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(long) ||
                expressionValue.Property.PropertyType == typeof(long?))
            {
                return(GetLong <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(float) ||
                expressionValue.Property.PropertyType == typeof(float?))
            {
                return(GetFloat <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(double) ||
                expressionValue.Property.PropertyType == typeof(double?))
            {
                return(GetDouble <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(decimal) ||
                expressionValue.Property.PropertyType == typeof(decimal?))
            {
                return(GetDecimal <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(bool) ||
                expressionValue.Property.PropertyType == typeof(bool?))
            {
                return(GetBoolean <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(DateTime) ||
                expressionValue.Property.PropertyType == typeof(DateTime?))
            {
                return(GetDateTime <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            if (expressionValue.Property.PropertyType == typeof(DateTimeOffset) ||
                expressionValue.Property.PropertyType == typeof(DateTimeOffset?))
            {
                return(GetDateTimeOffset <T>(parameter, context.arguments().value()[0], namingStrategy));
            }
            return(null);
        }
Beispiel #2
0
 public static bool TryParse <T>(ParameterExpression parameter,
                                 string selector, NamingStrategy namingStrategy, out ExpressionValue result
                                 )
 {
     result = null;
     try
     {
         result = Parse <T>(parameter, selector, namingStrategy);
         return(true);
     }
     catch
     {
         return(false);
     }
 }