示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class
        /// by parsing specified property expression string.
        /// </summary>
        /// <param name="expression">Property expression to parse.</param>
        internal static IExpression ParseProperty(string expression)
        {
            if (StringUtils.HasText(expression))
            {
                ExpressionLexer  lexer  = new ExpressionLexer(new StringReader(expression));
                ExpressionParser parser = new SpringExpressionParser(lexer);

                try
                {
                    parser.property();
                }
                catch (TokenStreamRecognitionException ex)
                {
                    throw new SyntaxErrorException(ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression);
                }
                return((IExpression)parser.getAST());
            }
            else
            {
                return(new Expression());
            }
        }
示例#2
0
        /// <summary>
        /// Returns MemberInfo for the specified property or field
        /// </summary>
        /// <param name="propertyOrFieldName">The name of the property or field to search for.</param>
        /// <returns>The <see cref="PropertyInfo"/> or <see cref="FieldInfo"/> for the specified property or field.</returns>
        /// <exception cref="FatalObjectException">If <paramref name="propertyOrFieldName"/> does not resolve to a property or field.</exception>
        private MemberInfo GetPropertyOrFieldInfo(string propertyOrFieldName)
        {
            if (StringUtils.IsNullOrEmpty(propertyOrFieldName))
            {
                throw new FatalObjectException("Can't find property or field info for null or zero length property name.");
            }

            try
            {
                IExpression propertyExpression = GetPropertyExpression(propertyOrFieldName);
                if (propertyExpression is PropertyOrFieldNode)
                {
                    return(((PropertyOrFieldNode)propertyExpression).GetMemberInfo(this.wrappedObject));
                }
                else if (propertyExpression is IndexerNode)
                {
                    return(((IndexerNode)propertyExpression).GetPropertyInfo(this.wrappedObject, null));
                }
                else if (propertyExpression is Expression)
                {
                    return(((Expression)propertyExpression).GetPropertyInfo(this.wrappedObject, null));
                }
                else
                {
                    throw new FatalObjectException("'" + propertyOrFieldName + "' is not a valid property or field expression.");
                }
            }
            catch (RecognitionException e)
            {
                throw new FatalObjectException("Failed to parse property or field name '" + propertyOrFieldName + "'.", e);
            }
            catch (TokenStreamRecognitionException e)
            {
                throw new FatalObjectException("Failed to parse property or field name '" + propertyOrFieldName + "'.", e);
            }
        }