Exemplo n.º 1
0
        private Csw.V202.XPathQueryableNavigator GetNavigator(ExpressionBuilderParameters parameters)
        {
            if (_Navigator == null)
            {
                Csw.V202.XPathQueryableNavigator xptn = new Csw.V202.XPathQueryableNavigator(parameters.ElementType);
                XPathNodeIterator xpni = xptn.Select(_Identifier.Symbol, parameters.NamespaceResolver, true);
                while (xpni.MoveNext())
                {
                    _Navigator = xpni.Current as Csw.V202.XPathQueryableNavigator;
                }

                Debug.Assert(_Navigator != null);
                if (_Navigator == null)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  SR.InvalidPropertyNameExpressionException,
                                  _Identifier.Symbol
                                  )
                              );
                }
            }

            return(_Navigator);
        }
Exemplo n.º 2
0
        private XPathTypeNavigator GetNavigator(ExpressionBuilderParameters parameters)
        {
            if (_Navigator == null)
            {
                XPathTypeNavigator xptn = parameters.CreateNavigator();
                XPathNodeIterator  xpni = xptn.Select(Untyped.Value, parameters.NamespaceResolver, true);
                while (xpni.MoveNext())
                {
                    _Navigator = xpni.Current as XPathTypeNavigator;
                }

                Debug.Assert(_Navigator != null);
                if (_Navigator == null)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  SR.InvalidPropertyNameExpressionException,
                                  Untyped.Value
                                  )
                              );
                }
            }

            return(_Navigator);
        }
Exemplo n.º 3
0
        internal LambdaExpression CreateLambda(IQueryable source, XmlNamespaceManager namespaceManager, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func<Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator=null)
        {
            Expression body=null;
            ParameterExpression[] parameters=new ParameterExpression[] {
                Expression.Parameter(source.ElementType)
            };

            if (Untyped.Elements().Any())
            {
                var ebp=new ExpressionBuilderParameters(parameters, source.Provider, source.ElementType, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, navigatorCreator);

                Type st=typeof(bool);
                if (logicOps!=null)
                    body=logicOps.CreateExpression(ebp, st, null);
                else if (comparisonOps!=null)
                    body=comparisonOps.CreateExpression(ebp, st, null);
                else if (spatialOps!=null)
                    body=spatialOps.CreateExpression(ebp, st, null);
            } else if (string.IsNullOrWhiteSpace(Untyped.Value))
                body=Expression.Constant(true, typeof(bool));

            if (body==null)
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        SR.InvalidFilterDefinitionException,
                        Untyped.Value
                    )
                );

            return Expression.Lambda(body, parameters);
        }
Exemplo n.º 4
0
 protected IEnumerable <Type> GetSubTypes(ExpressionBuilderParameters parameters)
 {
     using (IEnumerator <IExpressionBuilder> children = GetEnumerator())
         while (children.MoveNext())
         {
             yield return(children.Current.GetExpressionStaticType(parameters));
         }
 }
Exemplo n.º 5
0
 private Expression CreateStandardExpression(Expression subexpr, ExpressionBuilderParameters parameters, Type subType)
 {
     return(Expression.MakeUnary(
                _FilterElement.OperatorExpressionType,
                subexpr,
                null
                ));
 }
Exemplo n.º 6
0
        internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
        {
            if (Value != null)
            {
                return(Value.GetType());
            }

            return(typeof(object));
        }
Exemplo n.º 7
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func<Expression, ParameterExpression, Expression> operatorCreator)
        {
            // We only want literals in this case
            if (operatorCreator==null)
                return null;

            return GetNavigator(parameters)
                .CreateExpression(parameters.Parameters[0], expectedStaticType, operatorCreator);
        }
Exemplo n.º 8
0
 public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
 {
     if (_OptionalNot != null)
     {
         return(GetExpressionCreator().CreateExpression(parameters));
     }
     else
     {
         return(((IExpressionBuilder)_Primary).CreateExpression(parameters, expectedStaticType, null));
     }
 }
Exemplo n.º 9
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
        {
            Expression ret = Expression.Constant(GetValue(_Node, parameters), GetExpressionStaticType(parameters));

            if (operatorCreator != null)
            {
                ret = operatorCreator(ret, null);
            }

            return(ret);
        }
Exemplo n.º 10
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
        {
            // We only want literals in this case
            if (operatorCreator == null)
            {
                return(null);
            }

            return(GetNavigator(parameters)
                   .CreateExpression(parameters.Parameters[0], expectedStaticType, operatorCreator));
        }
Exemplo n.º 11
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func<Expression, ParameterExpression, Expression> operatorCreator)
        {
            if (!_Result.HasValue)
            {
                Csw.V202.XPathQueryableNavigator xptn=new Csw.V202.XPathQueryableNavigator(parameters.ElementType);
                XPathNodeIterator xpni=xptn.Select(_AttributeName.Identifier.Symbol, parameters.NamespaceResolver, true);
                _Result=xpni.MoveNext();
                if (_Negated)
                    _Result=!_Result;
            }

            return Expression.Constant(_Result.Value, typeof(bool));
        }
Exemplo n.º 12
0
            public Expression CreateExpression(ExpressionBuilderParameters parameters)
            {
                using (IEnumerator <IExpressionBuilder> children = GetEnumerator())
                    if (children.MoveNext() && (children.Current != null))
                    {
                        return(CreateStandardExpression(
                                   children.Current.CreateExpression(parameters, children.Current.GetExpressionStaticType(parameters), null),
                                   parameters,
                                   _FilterElement.GetExpressionStaticType(parameters)
                                   ));
                    }

                return(null);
            }
Exemplo n.º 13
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
        {
            if (!_Result.HasValue)
            {
                Csw.V202.XPathQueryableNavigator xptn = new Csw.V202.XPathQueryableNavigator(parameters.ElementType);
                XPathNodeIterator xpni = xptn.Select(_AttributeName.Identifier.Symbol, parameters.NamespaceResolver, true);
                _Result = xpni.MoveNext();
                if (_Negated)
                {
                    _Result = !_Result;
                }
            }

            return(Expression.Constant(_Result.Value, typeof(bool)));
        }
Exemplo n.º 14
0
        protected IEnumerable <object> GetConstants(ExpressionBuilderParameters parameters)
        {
            using (IEnumerator <IExpressionBuilder> children = GetEnumerator())
                while (children.MoveNext())
                {
                    object ret = null;

                    Expression exp = children.Current.CreateExpression(parameters, null, null);
                    if ((exp != null) && (exp.NodeType == LinqExpressionType.Constant))
                    {
                        ret = ((ConstantExpression)exp).Value;
                    }

                    yield return(ret);
                }
        }
Exemplo n.º 15
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters)
        {
            Expression ret=null;

            foreach (IExpressionCreator c in _Creators)
                if (ret!=null)
                    ret=Expression.MakeBinary(
                        _Combinator,
                        ret,
                        c.CreateExpression(parameters)
                    );
                else
                    ret=c.CreateExpression(parameters);

            return ret;
        }
Exemplo n.º 16
0
        internal LambdaExpression CreateLambda(IQueryable source, XmlNamespaceManager namespaceManager, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func <Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator = null)
        {
            Expression body = null;

            ParameterExpression[] parameters = new ParameterExpression[] {
                Expression.Parameter(source.ElementType)
            };

            if (Untyped.Elements().Any())
            {
                var ebp = new ExpressionBuilderParameters(parameters, source.Provider, source.ElementType, namespaceManager, mayRootPathBeImplied, operatorImplementationProvider, navigatorCreator);

                Type st = typeof(bool);
                if (logicOps != null)
                {
                    body = logicOps.CreateExpression(ebp, st, null);
                }
                else if (comparisonOps != null)
                {
                    body = comparisonOps.CreateExpression(ebp, st, null);
                }
                else if (spatialOps != null)
                {
                    body = spatialOps.CreateExpression(ebp, st, null);
                }
            }
            else if (string.IsNullOrWhiteSpace(Untyped.Value))
            {
                body = Expression.Constant(true, typeof(bool));
            }

            if (body == null)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              SR.InvalidFilterDefinitionException,
                              Untyped.Value
                              )
                          );
            }

            return(Expression.Lambda(body, parameters));
        }
Exemplo n.º 17
0
        public Expression CreateExpression(ExpressionBuilderParameters parameters)
        {
            Expression ret = null;

            foreach (IExpressionCreator c in _Creators)
            {
                if (ret != null)
                {
                    ret = Expression.MakeBinary(
                        _Combinator,
                        ret,
                        c.CreateExpression(parameters)
                        );
                }
                else
                {
                    ret = c.CreateExpression(parameters);
                }
            }

            return(ret);
        }
Exemplo n.º 18
0
        private XPathTypeNavigator GetNavigator(ExpressionBuilderParameters parameters)
        {
            if (_Navigator==null)
            {
                XPathTypeNavigator xptn=parameters.CreateNavigator();
                XPathNodeIterator xpni=xptn.Select(Untyped.Value, parameters.NamespaceResolver, true);
                while (xpni.MoveNext())
                    _Navigator=xpni.Current as XPathTypeNavigator;

                Debug.Assert(_Navigator!=null);
                if (_Navigator==null)
                    throw new InvalidOperationException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            SR.InvalidPropertyNameExpressionException,
                            Untyped.Value
                        )
                    );
            }

            return _Navigator;
        }
Exemplo n.º 19
0
        private Csw.V202.XPathQueryableNavigator GetNavigator(ExpressionBuilderParameters parameters)
        {
            if (_Navigator==null)
            {
                Csw.V202.XPathQueryableNavigator xptn=new Csw.V202.XPathQueryableNavigator(parameters.ElementType);
                XPathNodeIterator xpni=xptn.Select(_Identifier.Symbol, parameters.NamespaceResolver, true);
                while (xpni.MoveNext())
                    _Navigator=xpni.Current as Csw.V202.XPathQueryableNavigator;

                Debug.Assert(_Navigator!=null);
                if (_Navigator==null)
                    throw new InvalidOperationException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            SR.InvalidPropertyNameExpressionException,
                            _Identifier.Symbol
                        )
                    );
            }

            return _Navigator;
        }
Exemplo n.º 20
0
        internal protected virtual Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
        {
            var bop = this as IBinaryOperator;

            if (bop != null)
            {
                Type[] subtypes = bop.expression
                                  .Select <expression, Type>(e => ((IExpressionBuilder)e).GetExpressionStaticType(parameters))
                                  .Where <Type>(t => t != null)
                                  .ToArray <Type>();

                if (subtypes.Length == 0)
                {
                    return(null);
                }

                //TODO: probably needs more checking on other subtypes there...
                return(subtypes[0]);
            }

            return(null);
        }
Exemplo n.º 21
0
        private Expression CustomCallback(IEnumerator <IExpressionBuilder> children, LinkedList <Expression> subexpr, IEnumerator types, IEnumerator vals, Expression basexp, ParameterExpression pexp, MethodInfo method, object instance, ExpressionBuilderParameters parameters)
        {
            Expression ret = basexp;

            if (pexp != null)
            {
                Expression sub     = null;
                bool       hasNext = vals.MoveNext() && types.MoveNext();
                if (hasNext)
                {
                    children.MoveNext();
                    if (vals.Current == null)
                    {
                        sub = children.Current.CreateExpression(parameters, (Type)types.Current, (e, p) => CustomCallback(children, subexpr, types, vals, e, p, method, instance, parameters));
                    }
                    else
                    {
                        sub = CustomCallback(children, subexpr, types, vals, Expression.Constant(vals.Current, (Type)types.Current), null, method, instance, parameters);
                    }
                }
                else
                {
                    sub = subexpr.Last.Value;
                    subexpr.RemoveLast();
                }
                ret = CreateCustomExpression(method, instance, new Expression[] { ret, sub }, parameters, (Type)types.Current);
                if (!hasNext)
                {
                    subexpr.AddLast(ret);
                }
            }

            return(ret);
        }
Exemplo n.º 22
0
 internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return GetNavigator(parameters).Type;
 }
Exemplo n.º 23
0
 internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     // Cannot decide at this time
     return null;
 }
Exemplo n.º 24
0
 public Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return GetNavigator(parameters).Type;
 }
Exemplo n.º 25
0
 public Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
 {
     return(GetExpressionCreator().CreateExpression(parameters));
 }
Exemplo n.º 26
0
 protected override Expression CreateStandardExpression(IEnumerable <Expression> subexpr, ExpressionBuilderParameters parameters, Type subType)
 {
     throw new NotSupportedException("Only custom implementations are supported");
 }
Exemplo n.º 27
0
 internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     // Cannot decide at this time
     return(null);
 }
Exemplo n.º 28
0
        internal protected override Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func<Expression, ParameterExpression, Expression> operatorCreator)
        {
            Expression ret=null;

            if (expectedStaticType!=null)
            {
                object value=Untyped.Value;

                // Convert the string to the expectedStaticType
                switch (Type.GetTypeCode(expectedStaticType))
                {
                case TypeCode.Boolean:
                    value=XmlConvert.ToBoolean(Untyped.Value);
                    break;
                case TypeCode.Byte:
                    value=XmlConvert.ToByte(Untyped.Value);
                    break;
                case TypeCode.Char:
                    value=XmlConvert.ToChar(Untyped.Value);
                    break;
                case TypeCode.DateTime:
                    value=XmlConvert.ToDateTime(Untyped.Value, XmlDateTimeSerializationMode.RoundtripKind);
                    break;
                case TypeCode.Decimal:
                    value=XmlConvert.ToDecimal(Untyped.Value);
                    break;
                case TypeCode.Double:
                    value=XmlConvert.ToDouble(Untyped.Value);
                    break;
                case TypeCode.Int16:
                    value=XmlConvert.ToInt16(Untyped.Value);
                    break;
                case TypeCode.Int32:
                    value=XmlConvert.ToInt32(Untyped.Value);
                    break;
                case TypeCode.Int64:
                    value=XmlConvert.ToInt64(Untyped.Value);
                    break;
                case TypeCode.SByte:
                    value=XmlConvert.ToSByte(Untyped.Value);
                    break;
                case TypeCode.Single:
                    value=XmlConvert.ToSingle(Untyped.Value);
                    break;
                case TypeCode.String:
                    // We are already there
                    break;
                case TypeCode.UInt16:
                    value=XmlConvert.ToUInt16(Untyped.Value);
                    break;
                case TypeCode.UInt32:
                    value=XmlConvert.ToUInt32(Untyped.Value);
                    break;
                case TypeCode.UInt64:
                    value=XmlConvert.ToUInt64(Untyped.Value);
                    break;
                default:
                    if (expectedStaticType==typeof(DateTimeOffset))
                    {
                        value=XmlConvert.ToDateTimeOffset(Untyped.Value);
                    } else
                        // Last resort conversion
                        value=Convert.ChangeType(Untyped.Value, expectedStaticType, CultureInfo.InvariantCulture);
                    break;
                }

                ret=Expression.Constant(value, expectedStaticType);
            }

            if (ret==null)
            {
                Logger.Info(m => m("The literal \"{0}\" will be interpreted as a string by default", Untyped.Value));
                ret=Expression.Constant(Untyped.Value);
            }

            if (operatorCreator!=null)
                return operatorCreator(ret, null);

            return ret;
        }
Exemplo n.º 29
0
 protected abstract T GetValue(ParseTreeNode treeNode, ExpressionBuilderParameters parameters);
            protected override Expression CreateCustomExpression(MethodInfo method, object instance, IEnumerable <Expression> subexpr, ExpressionBuilderParameters parameters, Type subType)
            {
                Expression op = base.CreateCustomExpression(method, instance, subexpr, parameters, subType);

                Type rt = Nullable.GetUnderlyingType(method.ReturnType) ?? method.ReturnType;

                return(Expression.MakeBinary(
                           Node._OperatorExpression,
                           op,
                           Expression.Constant(Convert.ChangeType(Node._Tolerance.Value, rt, CultureInfo.InvariantCulture), method.ReturnType)
                           ));
            }
Exemplo n.º 31
0
 internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return(base.GetExpressionStaticType(parameters) ?? typeof(decimal));
 }
Exemplo n.º 32
0
 Type IExpressionBuilder.GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return typeof(bool);
 }
Exemplo n.º 33
0
        private Expression StandardCallback(IEnumerator <IExpressionBuilder> children, LinkedList <Expression> subexpr, Expression basexp, ParameterExpression pexp, ExpressionBuilderParameters parameters, Type expectedStaticType)
        {
            Expression ret = basexp;

            if (pexp != null)
            {
                Expression sub     = null;
                bool       hasNext = children.MoveNext();
                if (hasNext)
                {
                    sub = children.Current.CreateExpression(parameters, expectedStaticType, (e, p) => StandardCallback(children, subexpr, e, p, parameters, expectedStaticType));
                }
                else
                {
                    sub = subexpr.Last.Value;
                    subexpr.RemoveLast();
                }
                ret = CreateStandardExpression(new Expression[] { ret, sub }, parameters, expectedStaticType);
                if (!hasNext)
                {
                    subexpr.AddLast(ret);
                }
            }

            return(ret);
        }
Exemplo n.º 34
0
 internal protected virtual Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return(typeof(T));
 }
Exemplo n.º 35
0
        public virtual Expression CreateExpression(ExpressionBuilderParameters parameters)
        {
            Expression ret = null;

            List <Type> subTypes = GetSubTypes(parameters).ToList <Type>();
            Type        subtype  = subTypes.FirstOrDefault <Type>(t => t != null);

            subTypes = subTypes.Select <Type, Type>(t => t == null ? subtype : t).ToList <Type>();

            // Custom implementation
            if (parameters.OperatorImplementationProvider != null)
            {
                List <object> paramValues = GetConstants(parameters).ToList <object>();
                string        opname      = GetCustomImplementationName(subTypes, paramValues);

                Type[]     types  = subTypes.ToArray();
                object[]   values = paramValues.ToArray();
                object     instance;
                MethodInfo method = parameters.OperatorImplementationProvider.GetImplementation(opname, ref types, ref values, out instance);
                if (method != null)
                {
                    Debug.Assert(types.Length == values.Length);
                    using (IEnumerator <IExpressionBuilder> children = GetEnumerator())
                    {
                        IEnumerator             v       = values.GetEnumerator();
                        IEnumerator             t       = types.GetEnumerator();
                        LinkedList <Expression> subexpr = new LinkedList <Expression>();

                        while (v.MoveNext() && t.MoveNext())
                        {
                            children.MoveNext();
                            if (v.Current == null)
                            {
                                subexpr.AddLast(
                                    children.Current.CreateExpression(parameters, (Type)t.Current, (e, p) => CustomCallback(children, subexpr, t, v, e, p, method, instance, parameters))
                                    );
                            }
                            else
                            {
                                subexpr.AddLast(Expression.Constant(v.Current, (Type)t.Current));
                            }
                        }

                        if (subexpr.First != subexpr.Last)
                        {
                            ret = CreateCustomExpression(method, instance, subexpr, parameters, subtype);
                        }
                        else
                        {
                            ret = subexpr.First.Value;
                        }
                    }
                }
            }

            // Standard implementation
            if (ret == null)
            {
                using (IEnumerator <IExpressionBuilder> children = GetEnumerator())
                {
                    LinkedList <Expression> subexpr = new LinkedList <Expression>();

                    while (children.MoveNext())
                    {
                        subexpr.AddLast(
                            children.Current.CreateExpression(parameters, subtype, (e, p) => StandardCallback(children, subexpr, e, p, parameters, subtype))
                            );
                    }

                    if (subexpr.First != subexpr.Last)
                    {
                        ret = CreateStandardExpression(subexpr, parameters, subtype);
                    }
                    else
                    {
                        ret = subexpr.First.Value;
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 36
0
 Type IExpressionBuilder.GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return(GetExpressionStaticType(parameters));
 }
Exemplo n.º 37
0
        internal protected override Expression CreateExpression(ExpressionBuilderParameters parameters, Type expectedStaticType, Func <Expression, ParameterExpression, Expression> operatorCreator)
        {
            Expression ret = null;

            if (expectedStaticType != null)
            {
                object value = Untyped.Value;

                // Convert the string to the expectedStaticType
                switch (Type.GetTypeCode(expectedStaticType))
                {
                case TypeCode.Boolean:
                    value = XmlConvert.ToBoolean(Untyped.Value);
                    break;

                case TypeCode.Byte:
                    value = XmlConvert.ToByte(Untyped.Value);
                    break;

                case TypeCode.Char:
                    value = XmlConvert.ToChar(Untyped.Value);
                    break;

                case TypeCode.DateTime:
                    value = XmlConvert.ToDateTime(Untyped.Value, XmlDateTimeSerializationMode.RoundtripKind);
                    break;

                case TypeCode.Decimal:
                    value = XmlConvert.ToDecimal(Untyped.Value);
                    break;

                case TypeCode.Double:
                    value = XmlConvert.ToDouble(Untyped.Value);
                    break;

                case TypeCode.Int16:
                    value = XmlConvert.ToInt16(Untyped.Value);
                    break;

                case TypeCode.Int32:
                    value = XmlConvert.ToInt32(Untyped.Value);
                    break;

                case TypeCode.Int64:
                    value = XmlConvert.ToInt64(Untyped.Value);
                    break;

                case TypeCode.SByte:
                    value = XmlConvert.ToSByte(Untyped.Value);
                    break;

                case TypeCode.Single:
                    value = XmlConvert.ToSingle(Untyped.Value);
                    break;

                case TypeCode.String:
                    // We are already there
                    break;

                case TypeCode.UInt16:
                    value = XmlConvert.ToUInt16(Untyped.Value);
                    break;

                case TypeCode.UInt32:
                    value = XmlConvert.ToUInt32(Untyped.Value);
                    break;

                case TypeCode.UInt64:
                    value = XmlConvert.ToUInt64(Untyped.Value);
                    break;

                default:
                    if (expectedStaticType == typeof(DateTimeOffset))
                    {
                        value = XmlConvert.ToDateTimeOffset(Untyped.Value);
                    }
                    else
                    {
                        // Last resort conversion
                        value = Convert.ChangeType(Untyped.Value, expectedStaticType, CultureInfo.InvariantCulture);
                    }
                    break;
                }

                ret = Expression.Constant(value, expectedStaticType);
            }

            if (ret == null)
            {
                Logger.Info(m => m("The literal \"{0}\" will be interpreted as a string by default", Untyped.Value));
                ret = Expression.Constant(Untyped.Value);
            }

            if (operatorCreator != null)
            {
                return(operatorCreator(ret, null));
            }

            return(ret);
        }
Exemplo n.º 38
0
 protected abstract Expression CreateStandardExpression(IEnumerable <Expression> subexpr, ExpressionBuilderParameters parameters, Type subType);
Exemplo n.º 39
0
            protected override Expression CreateCustomExpression(MethodInfo method, object instance, IEnumerable <Expression> subexpr, ExpressionBuilderParameters parameters, Type subType)
            {
                Expression op = base.CreateCustomExpression(method, instance, subexpr, parameters, subType);

                Type rt = Nullable.GetUnderlyingType(method.ReturnType) ?? method.ReturnType;

                if (method.ReturnType == typeof(bool))
                {
                    return(op);
                }
                else
                {
                    return(Expression.Equal(
                               op,
                               Expression.Constant(Convert.ChangeType(true, rt, CultureInfo.InvariantCulture), method.ReturnType)
                               ));
                }
            }
Exemplo n.º 40
0
        protected virtual Expression CreateCustomExpression(MethodInfo method, object instance, IEnumerable <Expression> subexpr, ExpressionBuilderParameters parameters, Type subType)
        {
            Expression op = null;

            if (instance != null)
            {
                op = Expression.Call(
                    Expression.Constant(instance),
                    method,
                    subexpr
                    );
            }
            else
            {
                op = Expression.Call(
                    method,
                    subexpr
                    );
            }
            return(op);
        }
Exemplo n.º 41
0
 Type IExpressionBuilder.GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return(typeof(bool));
 }
Exemplo n.º 42
0
 internal protected override Type GetExpressionStaticType(ExpressionBuilderParameters parameters)
 {
     return base.GetExpressionStaticType(parameters) ?? typeof(decimal);
 }