|
From: <fab...@us...> - 2010-07-28 19:24:01
|
Revision: 5067
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5067&view=rev
Author: fabiomaulo
Date: 2010-07-28 19:23:54 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
Refactoring (extract interface)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs
Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs 2010-07-28 17:48:04 UTC (rev 5066)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/FunctionRegistry.cs 2010-07-28 19:23:54 UTC (rev 5067)
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
@@ -9,8 +8,8 @@
namespace NHibernate.Linq.Functions
{
- public class FunctionRegistry
- {
+ public class FunctionRegistry : ILinqToHqlGeneratorsRegistry
+ {
public static readonly FunctionRegistry Instance = new FunctionRegistry();
private readonly Dictionary<MethodInfo, IHqlGeneratorForMethod> registeredMethods = new Dictionary<MethodInfo, IHqlGeneratorForMethod>();
@@ -26,36 +25,6 @@
Register(new ICollectionGenerator());
}
- public IHqlGeneratorForMethod GetGenerator(MethodInfo method)
- {
- IHqlGeneratorForMethod methodGenerator;
-
- if (!TryGetMethodGenerator(method, out methodGenerator))
- {
- throw new NotSupportedException(method.ToString());
- }
-
- return methodGenerator;
- }
-
- public bool TryGetMethodGenerator(MethodInfo method, out IHqlGeneratorForMethod methodGenerator)
- {
- if (method.IsGenericMethod)
- {
- method = method.GetGenericMethodDefinition();
- }
-
- if (GetRegisteredMethodGenerator(method, out methodGenerator)) return true;
-
- // No method generator registered. Look to see if it's a standard LinqExtensionMethod
- if (GetStandardLinqExtensionMethodGenerator(method, out methodGenerator)) return true;
-
- // Not that either. Let's query each type generator to see if it can handle it
- if (GetMethodGeneratorForType(method, out methodGenerator)) return true;
-
- return false;
- }
-
private bool GetMethodGeneratorForType(MethodInfo method, out IHqlGeneratorForMethod methodGenerator)
{
methodGenerator = null;
@@ -105,7 +74,30 @@
return null;
}
- public void RegisterGenerator(MethodInfo method, IHqlGeneratorForMethod generator)
+ public bool TryGetGenerator(MethodInfo method, out IHqlGeneratorForMethod generator)
+ {
+ if (method.IsGenericMethod)
+ {
+ method = method.GetGenericMethodDefinition();
+ }
+
+ if (GetRegisteredMethodGenerator(method, out generator)) return true;
+
+ // No method generator registered. Look to see if it's a standard LinqExtensionMethod
+ if (GetStandardLinqExtensionMethodGenerator(method, out generator)) return true;
+
+ // Not that either. Let's query each type generator to see if it can handle it
+ if (GetMethodGeneratorForType(method, out generator)) return true;
+
+ return false;
+ }
+
+ public bool TryGetGenerator(MemberInfo property, out IHqlGeneratorForProperty generator)
+ {
+ return registeredProperties.TryGetValue(property, out generator);
+ }
+
+ public void RegisterGenerator(MethodInfo method, IHqlGeneratorForMethod generator)
{
registeredMethods.Add(method, generator);
}
Added: trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Linq/Functions/ILinqToHqlGeneratorsRegistry.cs 2010-07-28 19:23:54 UTC (rev 5067)
@@ -0,0 +1,12 @@
+using System.Reflection;
+
+namespace NHibernate.Linq.Functions
+{
+ public interface ILinqToHqlGeneratorsRegistry
+ {
+ bool TryGetGenerator(MethodInfo method, out IHqlGeneratorForMethod generator);
+ bool TryGetGenerator(MemberInfo property, out IHqlGeneratorForProperty generator);
+ void RegisterGenerator(MethodInfo method, IHqlGeneratorForMethod generator);
+ void RegisterGenerator(MemberInfo property, IHqlGeneratorForProperty generator);
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-07-28 17:48:04 UTC (rev 5066)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs 2010-07-28 19:23:54 UTC (rev 5067)
@@ -351,9 +351,10 @@
}
// Look for "special" properties (DateTime.Month etc)
- var generator = FunctionRegistry.GetGenerator(expression.Member);
+ IHqlGeneratorForProperty generator;
+ generator = FunctionRegistry.GetGenerator(expression.Member);
- if (generator != null)
+ if (generator != null)
{
return generator.BuildHql(expression.Member, expression.Expression, _hqlTreeBuilder, this);
}
@@ -394,9 +395,15 @@
protected HqlTreeNode VisitMethodCallExpression(MethodCallExpression expression)
{
- var generator = FunctionRegistry.GetGenerator(expression.Method);
+ IHqlGeneratorForMethod generator;
- return generator.BuildHql(expression.Method, expression.Object, expression.Arguments, _hqlTreeBuilder, this);
+ var method = expression.Method;
+ if (!FunctionRegistry.TryGetGenerator(method, out generator))
+ {
+ throw new NotSupportedException(method.ToString());
+ }
+
+ return generator.BuildHql(method, expression.Object, expression.Arguments, _hqlTreeBuilder, this);
}
protected HqlTreeNode VisitLambdaExpression(LambdaExpression expression)
Modified: trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs 2010-07-28 17:48:04 UTC (rev 5066)
+++ trunk/nhibernate/src/NHibernate/Linq/Visitors/SelectClauseVisitor.cs 2010-07-28 19:23:54 UTC (rev 5067)
@@ -82,7 +82,7 @@
{
// Depends if it's in the function registry
IHqlGeneratorForMethod methodGenerator;
- if (!FunctionRegistry.TryGetMethodGenerator(((MethodCallExpression) expression).Method, out methodGenerator))
+ if (!FunctionRegistry.TryGetGenerator(((MethodCallExpression) expression).Method, out methodGenerator))
{
return false;
}
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-28 17:48:04 UTC (rev 5066)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2010-07-28 19:23:54 UTC (rev 5067)
@@ -654,6 +654,7 @@
<Compile Include="Impl\SessionIdLoggingContext.cs" />
<Compile Include="Linq\Expressions\AggregateExpressionNode.cs" />
<Compile Include="Linq\EagerFetchingExtensionMethods.cs" />
+ <Compile Include="Linq\Functions\ILinqToHqlGeneratorsRegistry.cs" />
<Compile Include="Linq\LinqExtensionMethodAttribute.cs" />
<Compile Include="Linq\TypeHelperExtensionMethods.cs" />
<Compile Include="Linq\Visitors\NameUnNamedParameters.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|