Exemplo n.º 1
0
 private Type GetEnumType(BaseBlock block)
 {
     if (block is PropBlock)
     {
         PropBlock pExpr = (PropBlock)block;
         var       prop  = pExpr.Property;
         if (prop.IsDataProperty)
         {
             if (TypeFns.IsEnumType(prop.ReturnType))
             {
                 return(prop.ReturnType);
             }
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        // will return either a PropBlock or a LitBlock
        public static BaseBlock CreateRHSBlock(object exprSource,
                                               Type entityType, DataType otherExprDataType)
        {
            if (exprSource == null)
            {
                return(new LitBlock(exprSource, otherExprDataType));
            }

            if (exprSource is string)
            {
                var 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))
                {
                    return(new PropBlock(source, entityType));
                }
                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());
                }
                var value = exprMap["value"];

                if (exprMap.ContainsKey("isProperty"))
                {
                    return(new PropBlock((string)value, entityType));
                }
                else
                {
                    var dt       = (string)exprMap["dataType"];
                    var 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());
        }