/// <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()); } }
/// <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); } }
public void SurroundObjectWithEmptyStrings() { Assert.AreEqual(":Hi", StringUtils.Surround(string.Empty, new Foo("Hi"), string.Empty)); }
public void SurroundObject() { Assert.AreEqual("[:Hi]", StringUtils.Surround("[", new Foo("Hi"), "]")); }
public void SurroundNullWithNulls() { Assert.AreEqual(string.Empty, StringUtils.Surround(null, null)); }
public void FullSurroundObjectWithNulls() { Assert.AreEqual(":Hi", StringUtils.Surround(null, new Foo("Hi"), null)); }
public void GetAntExpressionsWithACoupleOfDuplicatedValidExpressions() { IList <string> actual = StringUtils.GetAntExpressions("${sigh}. Laura Palmer though... man, that sure was a tragedy. ${sigh}"); CheckGetAntExpressions(actual, "sigh"); }
public void SurroundEmptyStringWithEmptyStrings() { Assert.AreEqual(string.Empty, StringUtils.Surround(string.Empty, string.Empty)); }
public void FullSurroundNullWithEmptyStrings() { Assert.AreEqual(string.Empty, StringUtils.Surround(string.Empty, null, string.Empty)); }
public void ConvertUnsupportedEscapedCharacters() { string inputString = "what is this\\g"; Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString)); }
public void FullSurroundWithNulls() { Assert.AreEqual("Hi", StringUtils.Surround(null, "Hi", null)); }
public void FullSurround() { Assert.AreEqual("[Hi]", StringUtils.Surround("[", "Hi", "]")); }
public void GetAntExpressionsIgnoresEmptyExpression() { Assert.Throws <FormatException>(() => StringUtils.GetAntExpressions("This is an empty expression ${}...")); }
public void GetAntExpressionsWithMalformedExpression() { IList <string> actual = StringUtils.GetAntExpressions("Mmm... just what counts as ${a malformed{ expression?"); CheckGetAntExpressions(actual, new string[] {}); }
public void GetAntExpressionsWithACoupleOfUniqueValidExpressions() { IList <string> actual = StringUtils.GetAntExpressions("${Mmm}. Has there been any good telly since then... ${thinks}"); CheckGetAntExpressions(actual, "Mmm", "thinks"); }
public void ConvertEscapedCharactersNoEscapedCharacters() { string inputString = "foo bar is a funny term"; Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString)); }
public void GetAntExpressionsWithAValidExpression() { IList <string> actual = StringUtils.GetAntExpressions("${slurp}. Ah! That is one good cup of tea. That agent Cooper and his coffee... he sure was missing out on a good thing."); CheckGetAntExpressions(actual, "slurp"); }
public void ConvertEscapedCharactersAll() { string inputString = "newline\\n tab\\t return\\r"; Assert.AreEqual("newline\n tab\t return\r", StringUtils.ConvertEscapedCharacters(inputString)); }
public void Surround() { Assert.AreEqual("-Hi-", StringUtils.Surround("-", "Hi")); }
public void SurroundWithEmptyStrings() { Assert.AreEqual("Hi", StringUtils.Surround(string.Empty, "Hi")); }
public void GetAntExpressionsWithANestedExpression() { IList <string> actual = StringUtils.GetAntExpressions("And yeah, I've never been a fan of the doughnut... ${blechh${shudder}}"); CheckGetAntExpressions(actual, "blechh${shudder"); }