Esempio n. 1
0
        private BaseBlock ToExpression(Type entityType, DataType returnDataType)
        {
            var text = _sb.ToString();

            if (this._fnArgs == null)
            {
                if (PropertySignature.IsProperty(entityType, text))
                {
                    // TODO: we could check that the PropBlock dataType is compatible with the returnDataType
                    return(new PropBlock(text, entityType));
                }
                else
                {
                    return(new LitBlock(text, returnDataType));
                }
            }
            else
            {
                var fnName   = text;
                var argTypes = FnBlock.GetArgTypes(fnName);
                if (argTypes.Count != _fnArgs.Count)
                {
                    throw new Exception("Incorrect number of arguments to '" + fnName
                                        + "' function; was expecting " + argTypes.Count);
                }
                var exprs = _fnArgs.Select((token, ix) => token.ToExpression(entityType, argTypes[ix])).ToList();
                // TODO: we could check that the FnBlock dataType is compatible with the returnDataType
                return(new FnBlock(text, exprs));
            }
        }
Esempio n. 2
0
        // will return either a PropBlock or a FnBlock
        public static BaseBlock CreateLHSBlock(object exprSource,
                                               Type entityType)
        {
            if (exprSource == null)
            {
                throw new Exception(
                          "Null expressions are only permitted on the right hand side of a BinaryPredicate");
            }

            if (exprSource is IDictionary)
            {
                throw new Exception(
                          "Object expressions are only permitted on the right hand side of a BinaryPredicate");
            }

            if (exprSource is IList)
            {
                throw new Exception(
                          "Array expressions are only permitted on the right hand side of a BinaryPredicate");
            }

            if (!(exprSource is string))
            {
                throw new Exception(
                          "Only string expressions are permitted on this predicate");
            }

            var source = (string)exprSource;

            if (source.IndexOf("(") == -1)
            {
                return(new PropBlock(source, entityType));
            }
            else
            {
                return(FnBlock.CreateFrom(source, entityType));
            }
        }