Esempio n. 1
0
        private static string MemberExpressionToString(MemberExpression memberExpression)
        {
            if (memberExpression.Type == typeof(DateTime))
            {
                if (memberExpression.Member.Name == "UtcNow")
                {
                    return(BuiltIn.Function.UtcNow);
                }
                // TODO: throw exception for any other DateTime type as not supported
            }

            if (memberExpression.Type.GetInterfaces().Any(x => x == typeof(IEnumerable <string>)))
            {
                object result = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
                return(ExpressionToString(Expression.Constant(result)));
            }

            if (memberExpression.Expression.NodeType == ExpressionType.Parameter)
            {
                var eventFieldMemberExpression = new EventFieldMemberExpression(memberExpression);

                return(eventFieldMemberExpression.EscapedEventFieldName);
            }

            if (memberExpression.Expression.NodeType == ExpressionType.Constant)
            {
                object result = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
                return(ConvertObjectToString(result));
            }

            throw new NotImplementedException();
        }
Esempio n. 2
0
        internal static Property Create <TY>(Expression <Func <TY, T> > property)
        {
            var eventFieldMemberExpression = new EventFieldMemberExpression(property.Body as MemberExpression);

            if (BuiltIn.All().Contains(eventFieldMemberExpression.UnescapedEventFieldName))
            {
                return(Property.BuiltIn(eventFieldMemberExpression.UnescapedEventFieldName));
            }
            return(Property.Custom(eventFieldMemberExpression.UnescapedEventFieldName, eventFieldMemberExpression.EventFieldDataType));
        }