示例#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));
            }
        }
示例#2
0
        // will return either a PropBlock or a LitBlock
        #region Modified code - Added entityMetadataProvider parameter
        public static BaseBlock CreateRHSBlock(Object exprSource,
                                               Type entityType, DataType otherExprDataType, IEntityMetadataProvider entityMetadataProvider)
        {
            if (exprSource == null)
            {
                return(new LitBlock(exprSource, otherExprDataType));
            }

            if (exprSource is String)
            {
                String source = (String)exprSource;
                if (entityType == null)
                {
                    // if entityType is unknown then assume that the rhs is a
                    // literal
                    return(new LitBlock(source, otherExprDataType));
                }

                if (PropertySignature.IsProperty(entityType, source, entityMetadataProvider))
                {
                    return(new PropBlock(source, entityType, entityMetadataProvider));
                }
                else
                {
                    return(new LitBlock(source, otherExprDataType));
                }
            }

            if (TypeFns.IsPredefinedType(exprSource.GetType()))
            {
                return(new LitBlock(exprSource, otherExprDataType));
            }

            if (exprSource is IDictionary <string, Object> )
            {
                var exprMap = (IDictionary <string, Object>)exprSource;
                // note that this is NOT the same a using get and checking for null
                // because null is a valid 'value'.
                if (!exprMap.ContainsKey("value"))
                {
                    throw new Exception(
                              "Unable to locate a 'value' property on: "
                              + exprMap.ToString());
                }
                Object value = exprMap["value"];

                if (exprMap.ContainsKey("isProperty"))
                {
                    return(new PropBlock((String)value, entityType, entityMetadataProvider));
                }
                else
                {
                    String   dt       = (String)exprMap["dataType"];
                    DataType dataType = (dt != null) ? DataType.FromName(dt) : otherExprDataType;
                    return(new LitBlock(value, dataType));
                }
            }

            if (exprSource is IList)
            {
                // right now this pretty much implies the values on an 'in' clause
                return(new LitBlock(exprSource, otherExprDataType));
            }

            if (TypeFns.IsEnumType(exprSource.GetType()))
            {
                return(new LitBlock(exprSource, otherExprDataType));
            }

            throw new Exception(
                      "Unable to parse the right hand side of this BinaryExpression: "
                      + exprSource.ToString());
        }