Example #1
0
        private static string Process(this ConstantExpression constantExpression)
        {
            var stringify = _stringificationRulesResolver.RequiresStringification(constantExpression.Type);
            var value     = constantExpression.Value;

            var converter   = ConverterExtensions.GetConverter(null, constantExpression.Type);
            var valueString = converter.ConvertBack(value);

            if (valueString == null)
            {
                return(null);
            }

            return(stringify ? valueString.WrapWithQuotes() : valueString);
        }
Example #2
0
        private static string CompileExpression(Expression expression)
        {
            var stringify = _stringificationRulesResolver.RequiresStringification(expression.Type);

            var unaryExpression  = Expression.Convert(expression, typeof(object));
            var getterExpression = Expression.Lambda <Func <object> >(unaryExpression);
            var getter           = getterExpression.Compile();
            var value            = getter();

            var converter   = ConverterExtensions.GetConverter(null, expression.Type);
            var valueString = converter.ConvertBack(value);

            if (valueString == null)
            {
                return(null);
            }

            return(stringify ? valueString.WrapWithQuotes() : valueString);
        }