title: How to access argument properties when writing custom NHibernate HQL generator
body: <p>I have the following custom type with a method on it to determine if one span of time overlaps another</p>
  
  <pre><code>public struct DateTimeSpan
  {
      public DateTime? Start { get; set; }
      public DateTime? End { get; set; }
  
      public bool Overlaps(DateTimeSpan overlap)
      {
          //....
      }
  }
  </code></pre>
  
  <p>I am trying to write a custom HQL generator so that when I use this method within my data access LINQ queries it will generate to appropriate SQL when querying the database.</p>
  
  <p>This is the start of my <code>BaseHqlGeneratorForMethod</code> that attempts to compare the <code>End</code> property of one <code>DateTimeSpan</code> with the other</p>
  
  <pre><code>public class DateSpanOverlapsDateTimeSpanHqlGenerator : BaseHqlGeneratorForMethod
  {
      public DateSpanOverlapsDateTimeSpanHqlGenerator()
      {
          SupportedMethods = new[]
              {
                  ReflectionHelper.GetMethodDefinition&lt;DateTimeSpan&gt;(x =&gt; x.Overlaps(new DateTimeSpan()))
              };
      }
  
      public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection&lt;Expression&gt; arguments, HqlTreeBuilder builder, IHqlExpressionVisitor visitor)
      {
          var endTargetProperty = ReflectionHelper.GetProperty&lt;DateTimeSpan, DateTime?&gt;(x =&gt; x.End);
          Expression endTargetExpression = Expression.MakeMemberAccess(targetObject, endTargetProperty);
  
          var endArgumentProperty = ReflectionHelper.GetProperty&lt;DateTimeSpan, DateTime?&gt;(x =&gt; x.End);
          Expression endArgumentExpression = Expression.MakeMemberAccess(arguments[0], endArgumentProperty);
  
         return builder.GreaterThanOrEqual(visitor.Visit(endTargetExpression).AsExpression(), visitor.Visit(endArgumentExpression).AsExpression());
      }
  }
  </code></pre>
  
  <p>I have proven that the <code>End</code> property in the <code>targetObject</code> is being evaluated fine but no matter what I do I cannot get it to evaluate the <code>End</code> property in <code>arguments[0]</code>.  The above code is just one example of what I have tried (and seems the most obvious given it works for the <code>targetObject</code>) with most things I try ending up with the exception <code>Antlr.Runtime.NoViableAltException</code></p>
  
  <p>One obvious different between <code>targetObject</code> and <code>arguments[0]</code> is that <code>targetObject</code> is of type <code>PropertyExpression</code> and <code>arguments[0]</code> is of type <code>ConstantExpression</code>.  I assume this means there needs to be different ways to access them but I cannot work out what it is!</p>