Results 1 to 3 of 3

Thread: ExpressionEvaluator Cast in Parse expression

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Default ExpressionEvaluator Cast in Parse expression

    Here's my problem: I am trying to use spring.net's ExpressionEvaluator.getValue function in the following way:

    bool retVal = (bool)ExpressionEvaluator.getValue(mailMessage, "Subject.Contains('vijay')");

    the 'mailMessage' object falls into a concrete type of a 'IMailMessage' interface which has a 'Subject' property in its contract.

    Now the issue is mailMessage object's class has implemented the IMailMessage interface explicitly which is why the expressionevaluator is trying to use ConcreteImplementation.Subject and is failing since it has to use 'IMailMessage.Subject'.

    What could be the best way to do this, I certainly dont want to implement implicitly.

    Or is there a way to cast within the expression?

  2. #2
    Join Date
    Jul 2010
    Posts
    245

    Default

    To access the explicit implementation, you need to change your SPeL expression to the following:

    bool retVal = (bool)ExpressionEvaluator.getValue(mailMessage, "'IMailMessage.Subject'.Contains('vijay')");

    ( note the single quotes (') surrounding 'IMailMessage.Subject' )

    In my tests, this worked.

    -Steve B.

  3. #3
    Join Date
    Mar 2011
    Posts
    25

    Default

    Well, in my test it does not work:

    Code:
        [TestFixture]
        public class Q10150013EvaluateExplicitlyImplementedProperty
        {
            [Test]
            public void First_test()
            {
                var mm = (IMailMessage) new MailMessage();
                mm.Subject = "abc vijay def";
                var val = (bool)ExpressionEvaluator.GetValue(mm, "'IMailMessage.Subject'.Contains('vijay')");
                Console.WriteLine(val);
                Assert.True(val);
            }
        }
    
        public interface IMailMessage
        {
            string Subject { get; set; }
        }
    
        public class MailMessage : IMailMessage
        {
            string IMailMessage.Subject { get; set; }
        }
    The expression evaluator considers 'IMailMessage.Subject' to be a plain string and does not evaluate anything against the root.

    Maybe you ran your test against SPEL Java (lower capital g in your reply) and this is difference between Java and .net implementations?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •