Beispiel #1
0
        private BaseBlock ToExpression(Type entityType, DataType returnDataType)
        {
            String 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
            {
                String 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));
            }
        }
Beispiel #2
0
        // will return either a PropBlock or a FnBlock
        #region Modified code - Added entityMetadataProvider parameter
        public static BaseBlock CreateLHSBlock(Object exprSource,
                                               Type entityType, IEntityMetadataProvider entityMetadataProvider)
        {
            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");
            }

            String source = (String)exprSource;

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