1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Collections . ObjectModel ;
4
3
using System . Linq ;
5
4
using System . Linq . Expressions ;
9
8
10
9
namespace NHibernate . Linq . Functions
11
10
{
12
- public class FunctionRegistry
13
- {
11
+ public class FunctionRegistry : ILinqToHqlGeneratorsRegistry
12
+ {
14
13
public static readonly FunctionRegistry Instance = new FunctionRegistry ( ) ;
15
14
16
15
private readonly Dictionary < MethodInfo , IHqlGeneratorForMethod > registeredMethods = new Dictionary < MethodInfo , IHqlGeneratorForMethod > ( ) ;
@@ -26,36 +25,6 @@ private FunctionRegistry()
26
25
Register ( new ICollectionGenerator ( ) ) ;
27
26
}
28
27
29
- public IHqlGeneratorForMethod GetGenerator ( MethodInfo method )
30
- {
31
- IHqlGeneratorForMethod methodGenerator ;
32
-
33
- if ( ! TryGetMethodGenerator ( method , out methodGenerator ) )
34
- {
35
- throw new NotSupportedException ( method . ToString ( ) ) ;
36
- }
37
-
38
- return methodGenerator ;
39
- }
40
-
41
- public bool TryGetMethodGenerator ( MethodInfo method , out IHqlGeneratorForMethod methodGenerator )
42
- {
43
- if ( method . IsGenericMethod )
44
- {
45
- method = method . GetGenericMethodDefinition ( ) ;
46
- }
47
-
48
- if ( GetRegisteredMethodGenerator ( method , out methodGenerator ) ) return true ;
49
-
50
- // No method generator registered. Look to see if it's a standard LinqExtensionMethod
51
- if ( GetStandardLinqExtensionMethodGenerator ( method , out methodGenerator ) ) return true ;
52
-
53
- // Not that either. Let's query each type generator to see if it can handle it
54
- if ( GetMethodGeneratorForType ( method , out methodGenerator ) ) return true ;
55
-
56
- return false ;
57
- }
58
-
59
28
private bool GetMethodGeneratorForType ( MethodInfo method , out IHqlGeneratorForMethod methodGenerator )
60
29
{
61
30
methodGenerator = null ;
@@ -105,7 +74,30 @@ public IHqlGeneratorForProperty GetGenerator(MemberInfo member)
105
74
return null ;
106
75
}
107
76
108
- public void RegisterGenerator ( MethodInfo method , IHqlGeneratorForMethod generator )
77
+ public bool TryGetGenerator ( MethodInfo method , out IHqlGeneratorForMethod generator )
78
+ {
79
+ if ( method . IsGenericMethod )
80
+ {
81
+ method = method . GetGenericMethodDefinition ( ) ;
82
+ }
83
+
84
+ if ( GetRegisteredMethodGenerator ( method , out generator ) ) return true ;
85
+
86
+ // No method generator registered. Look to see if it's a standard LinqExtensionMethod
87
+ if ( GetStandardLinqExtensionMethodGenerator ( method , out generator ) ) return true ;
88
+
89
+ // Not that either. Let's query each type generator to see if it can handle it
90
+ if ( GetMethodGeneratorForType ( method , out generator ) ) return true ;
91
+
92
+ return false ;
93
+ }
94
+
95
+ public bool TryGetGenerator ( MemberInfo property , out IHqlGeneratorForProperty generator )
96
+ {
97
+ return registeredProperties . TryGetValue ( property , out generator ) ;
98
+ }
99
+
100
+ public void RegisterGenerator ( MethodInfo method , IHqlGeneratorForMethod generator )
109
101
{
110
102
registeredMethods . Add ( method , generator ) ;
111
103
}
0 commit comments