PageRenderTime 64ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NHibernate.Spatial/src/NHibernate.Spatial/Linq/Functions/SpatialPropertyGenerator.cs

https://bitbucket.org/dabide/nhcontrib
C# | 36 lines | 33 code | 3 blank | 0 comment | 2 complexity | 662c1954ca4e26cea173146a966e6691 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, Apache-2.0, LGPL-3.0, LGPL-2.1
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using System.Reflection;
  5. using GeoAPI.Geometries;
  6. using NHibernate.Hql.Ast;
  7. using NHibernate.Linq;
  8. using NHibernate.Linq.Functions;
  9. using NHibernate.Linq.Visitors;
  10. using NHibernate.Spatial.Dialect;
  11. namespace NHibernate.Spatial.Linq.Functions
  12. {
  13. public abstract class SpatialPropertyGenerator<TGeometry, TResult> : BaseHqlGeneratorForProperty
  14. where TGeometry : IGeometry
  15. {
  16. protected SpatialPropertyGenerator(params Expression<Func<TGeometry, TResult>>[] expressions)
  17. {
  18. SupportedProperties = expressions.Select(o => ReflectionHelper.GetProperty(o)).ToArray();
  19. }
  20. public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
  21. {
  22. var methodCall = treeBuilder.MethodCall(SpatialDialect.HqlPrefix + member.Name, new[]
  23. {
  24. visitor.Visit(expression).AsExpression()
  25. });
  26. if (typeof(TResult) == typeof(bool))
  27. {
  28. return treeBuilder.Equality(methodCall, treeBuilder.True());
  29. }
  30. return methodCall;
  31. }
  32. }
  33. }