title: How to get Property Value from MemberExpression without .Compile()?
body: <p>I'm having issues trying to get the value of an object out of the Expression Tree without using .Compile()</p>
  
  <p>The object is quite simple.</p>
  
  <pre><code>var userModel = new UserModel { Email = "John@Doe.com"};
  </code></pre>
  
  <p>The method giving me issues looks like this.</p>
  
  <pre><code>private void VisitMemberAccess(MemberExpression expression, MemberExpression left)
  {
      var key = left != null ? left.Member.Name : expression.Member.Name;
      if (expression.Expression.NodeType.ToString() == "Parameter")
      {
          // add the string key
          _strings.Add(string.Format("[{0}]", key));
      }
      else
      {
          // add the string parameter
          _strings.Add(string.Format("@{0}", key));
  
          // Potential NullReferenceException
          var val = (expression.Member as FieldInfo).GetValue((expression.Expression as ConstantExpression).Value);
  
          // add parameter value
          Parameters.Add("@" + key, val);
      }
  }
  </code></pre>
  
  <p>The tests I'm running are quite simple</p>
  
  <pre><code>[Test]  // PASS
  public void ShouldVisitExpressionByGuidObject ()
  {
      // Setup
      var id = new Guid( "CCAF57D9-88A4-4DCD-87C7-DB875E0D4E66" );
      const string expectedString = "[Id] = @Id";
      var expectedParameters = new Dictionary&lt;string, object&gt; { { "@Id", id } };
  
      // Execute
      var actualExpression = TestExpression&lt;UserModel&gt;( u =&gt; u.Id == id );
      var actualParameters = actualExpression.Parameters;
      var actualString = actualExpression.WhereExpression;
  
      // Test
      Assert.AreEqual( expectedString, actualString );
      CollectionAssert.AreEquivalent( expectedParameters, actualParameters );
  }
  </code></pre>
  
  
  
  <pre><code>[Test]  // FAIL [System.NullReferenceException : Object reference not set to an instance of an object.]
  public void ShouldVisitExpressionByStringObject ()
  {
      // Setup
      var expectedUser = new UserModel {Email = "john@doe.com"};
  
      const string expectedString = "[Email] = @Email";
      var expectedParameters = new Dictionary&lt;string, object&gt; { { "@Email", expectedUser.Email } };
  
      // Execute
      var actualExpression = TestExpression&lt;UserModel&gt;( u =&gt; u.Email == expectedUser.Email );
      var actualParameters = actualExpression.Parameters;
      var actualString = actualExpression.WhereExpression;
  
      // Assert
      Assert.AreEqual( expectedString, actualString );
      CollectionAssert.AreEquivalent( expectedParameters, actualParameters );
  }
  </code></pre>
  
  <hr>
  
  <p>I should note that changing</p>
  
  <pre><code>var val = (expression.Member as FieldInfo).GetValue((expression.Expression as ConstantExpression).Value);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>var val = Expression.Lambda( expression ).Compile().DynamicInvoke().ToString();
  </code></pre>
  
  <p>will allow the test to pass, however this code needs to run on iOS, and therefore can't use <code>.Compile()</code></p>