Question

I use Spring.Core dll with ExpressionEvaluator .

My simple code:

public void ComputedFields()
{
  var finance = new Finance();
  ExpressionEvaluator
    .SetValue(
      finance, 
      "FieldToBeSet", 
      ExpressionEvaluator
        .GetValue(
          finance, 
          "SomeNullableFinanceField.GetValueOrDefault(1)"));

  Assert.AreEqual(finance.FieldToBeSet, 1);
} 

raises the following exception:

Method GetValueOrDefault with the specified number and types of arguments does not exist.

Finance is a simple poco the SomeNullableFinanceField field is of type decimal?

Was it helpful?

Solution

Spring.net ExpressionEvaluator doesn't know about .net Nullable types, so it doesn't try to find and invoke GetValueOrDefault method because of SomeNullableFinanceField is null.

If SomeNullableFinanceField is not null, it tries to invoke GetValueOrDefault on SomeNullableFinanceField value (decimal).

You should modify you expression:

ExpressionEvaluator
    .GetValue(
      finance, 
      "SomeNullableFinanceField != null ? SomeNullableFinanceField : 1");

or

ExpressionEvaluator
    .GetValue(
      finance, 
      "{SomeNullableFinanceField, 1}.nonNull()[0]");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top