@@ -10,19 +10,55 @@ internal class MethodFinder
10
10
private readonly ParsingConfig _parsingConfig ;
11
11
private readonly IExpressionHelper _expressionHelper ;
12
12
13
+ /// <summary>
14
+ /// #794
15
+ /// </summary>
16
+ private interface IAggregateSignatures
17
+ {
18
+ void Average ( decimal ? selector ) ;
19
+ void Average ( decimal selector ) ;
20
+ void Average ( double ? selector ) ;
21
+ void Average ( double selector ) ;
22
+ void Average ( float ? selector ) ;
23
+ void Average ( float selector ) ;
24
+ void Average ( int ? selector ) ;
25
+ void Average ( int selector ) ;
26
+ void Average ( long ? selector ) ;
27
+ void Average ( long selector ) ;
28
+
29
+ void Sum ( decimal ? selector ) ;
30
+ void Sum ( decimal selector ) ;
31
+ void Sum ( double ? selector ) ;
32
+ void Sum ( double selector ) ;
33
+ void Sum ( float ? selector ) ;
34
+ void Sum ( float selector ) ;
35
+ void Sum ( int ? selector ) ;
36
+ void Sum ( int selector ) ;
37
+ void Sum ( long ? selector ) ;
38
+ void Sum ( long selector ) ;
39
+ }
40
+
13
41
public MethodFinder ( ParsingConfig parsingConfig , IExpressionHelper expressionHelper )
14
42
{
15
43
_parsingConfig = Check . NotNull ( parsingConfig ) ;
16
44
_expressionHelper = Check . NotNull ( expressionHelper ) ;
17
45
}
18
46
47
+ public void CheckAggregateMethodAndTryUpdateArgsToMatchMethodArgs ( string methodName , ref Expression [ ] args )
48
+ {
49
+ if ( methodName is nameof ( IAggregateSignatures . Average ) or nameof ( IAggregateSignatures . Sum ) )
50
+ {
51
+ ContainsMethod ( typeof ( IAggregateSignatures ) , methodName , false , null , ref args ) ;
52
+ }
53
+ }
54
+
19
55
public bool ContainsMethod ( Type type , string methodName , bool staticAccess = true )
20
56
{
21
57
Check . NotNull ( type ) ;
22
58
23
59
#if ! ( NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD )
24
- var flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
25
- return type . FindMembers ( MemberTypes . Method , flags , Type . FilterNameIgnoreCase , methodName ) . Any ( ) ;
60
+ var flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
61
+ return type . FindMembers ( MemberTypes . Method , flags , Type . FilterNameIgnoreCase , methodName ) . Any ( ) ;
26
62
#else
27
63
return type . GetTypeInfo ( ) . DeclaredMethods . Any ( m => ( m . IsStatic || ! staticAccess ) && m . Name . Equals ( methodName , StringComparison . OrdinalIgnoreCase ) ) ;
28
64
#endif
@@ -40,17 +76,17 @@ public bool ContainsMethod(Type type, string methodName, bool staticAccess, Expr
40
76
41
77
public int FindMethod ( Type ? type , string methodName , bool staticAccess , ref Expression ? instance , ref Expression [ ] args , out MethodBase ? method )
42
78
{
43
- #if ! ( NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD )
44
- BindingFlags flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
45
- foreach ( Type t in SelfAndBaseTypes ( type ) )
79
+ #if ! ( NETFX_CORE || WINDOWS_APP || UAP10_0 || NETSTANDARD )
80
+ BindingFlags flags = BindingFlags . Public | BindingFlags . DeclaredOnly | ( staticAccess ? BindingFlags . Static : BindingFlags . Instance ) ;
81
+ foreach ( Type t in SelfAndBaseTypes ( type ) )
82
+ {
83
+ MemberInfo [ ] members = t . FindMembers ( MemberTypes . Method , flags , Type . FilterNameIgnoreCase , methodName ) ;
84
+ int count = FindBestMethodBasedOnArguments ( members . Cast < MethodBase > ( ) , ref args , out method ) ;
85
+ if ( count != 0 )
46
86
{
47
- MemberInfo [ ] members = t . FindMembers ( MemberTypes . Method , flags , Type . FilterNameIgnoreCase , methodName ) ;
48
- int count = FindBestMethodBasedOnArguments ( members . Cast < MethodBase > ( ) , ref args , out method ) ;
49
- if ( count != 0 )
50
- {
51
- return count ;
52
- }
87
+ return count ;
53
88
}
89
+ }
54
90
#else
55
91
foreach ( Type t in SelfAndBaseTypes ( type ) )
56
92
{
0 commit comments