forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumerableHelper.cs
93 lines (86 loc) · 3.46 KB
/
EnumerableHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using NHibernate.Util;
namespace NHibernate.Linq
{
// Since v5
[Obsolete("Please use NHibernate.Util.ReflectHelper instead")]
public static class ReflectionHelper
{
/// <summary>
/// Extract the <see cref="MethodInfo"/> from a given expression.
/// </summary>
/// <typeparam name="TSource">The declaring-type of the method.</typeparam>
/// <param name="method">The method.</param>
/// <returns>The <see cref="MethodInfo"/> of the no-generic method or the generic-definition for a generic-method.</returns>
/// <seealso cref="MethodInfo.GetGenericMethodDefinition"/>
public static MethodInfo GetMethodDefinition<TSource>(Expression<Action<TSource>> method)
{
return ReflectHelper.GetMethodDefinition(method);
}
/// <summary>
/// Extract the <see cref="MethodInfo"/> from a given expression.
/// </summary>
/// <typeparam name="TSource">The declaring-type of the method.</typeparam>
/// <param name="method">The method.</param>
/// <returns>The <see cref="MethodInfo"/> of the method.</returns>
public static MethodInfo GetMethod<TSource>(Expression<Action<TSource>> method)
{
return ReflectHelper.GetMethod(method);
}
/// <summary>
/// Extract the <see cref="MethodInfo"/> from a given expression.
/// </summary>
/// <param name="method">The method.</param>
/// <returns>The <see cref="MethodInfo"/> of the no-generic method or the generic-definition for a generic-method.</returns>
/// <seealso cref="MethodInfo.GetGenericMethodDefinition"/>
public static MethodInfo GetMethodDefinition(Expression<System.Action> method)
{
return ReflectHelper.GetMethodDefinition(method);
}
/// <summary>
/// Extract the <see cref="MethodInfo"/> from a given expression.
/// </summary>
/// <param name="method">The method.</param>
/// <returns>The <see cref="MethodInfo"/> of the method.</returns>
public static MethodInfo GetMethod(Expression<System.Action> method)
{
return ReflectHelper.GetMethod(method);
}
/// <summary>
/// Gets the field or property to be accessed.
/// </summary>
/// <typeparam name="TSource">The declaring-type of the property.</typeparam>
/// <typeparam name="TResult">The type of the property.</typeparam>
/// <param name="property">The expression representing the property getter.</param>
/// <returns>The <see cref="MemberInfo"/> of the property.</returns>
public static MemberInfo GetProperty<TSource, TResult>(Expression<Func<TSource, TResult>> property)
{
return ReflectHelper.GetProperty(property);
}
}
// Since v5
[Obsolete("Please use NHibernate.Util.ReflectHelper instead")]
public static class EnumerableHelper
{
public static MethodInfo GetMethod(string name, System.Type[] parameterTypes)
{
return typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(m => m.Name == name &&
ReflectHelper.ParameterTypesMatch(m.GetParameters(), parameterTypes))
.Single();
}
public static MethodInfo GetMethod(string name, System.Type[] parameterTypes, System.Type[] genericTypeParameters)
{
return typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(m => m.Name == name &&
m.ContainsGenericParameters &&
m.GetGenericArguments().Count() == genericTypeParameters.Length &&
ReflectHelper.ParameterTypesMatch(m.GetParameters(), parameterTypes))
.Single()
.MakeGenericMethod(genericTypeParameters);
}
}
}