forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReflectionCache.cs
59 lines (50 loc) · 2.85 KB
/
ReflectionCache.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
using System;
using System.Linq;
using System.Reflection;
using NHibernate.Linq;
namespace NHibernate.Util
{
internal static class ReflectionCache
{
// When adding a method to this cache, please follow the naming convention of those subclasses and fields:
// - Add your method to a subclass named according to the type holding the method, and suffixed with "Methods".
// - Name the field according to the method name.
// - If the method has overloads, suffix it with "With" followed by its parameter names. Do not list parameters
// common to all overloads.
// - If the method is a generic method definition, add "Definition" as final suffix.
// - If the method is generic, suffix it with "On" followed by its generic parameter type names.
// Avoid caching here narrow cases, such as those using specific types and unlikely to be used by many classes.
// Cache them instead in classes using them.
internal static class EnumerableMethods
{
internal static readonly MethodInfo AggregateDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object>(null, null));
internal static readonly MethodInfo AggregateWithSeedDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object, object>(null, null, null));
internal static readonly MethodInfo AggregateWithSeedAndResultSelectorDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate<object, object, object>(null, null, null, null));
internal static readonly MethodInfo CastDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.Cast<object>(null));
internal static readonly MethodInfo GroupByWithElementSelectorDefinition = ReflectionHelper.GetMethodDefinition(
() => Enumerable.GroupBy<object, object, object>(null, null, (Func<object, object>)null));
internal static readonly MethodInfo SelectDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.Select<object, object>(null, (Func<object, object>)null));
internal static readonly MethodInfo ToArrayDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.ToArray<object>(null));
internal static readonly MethodInfo ToListDefinition =
ReflectionHelper.GetMethodDefinition(() => Enumerable.ToList<object>(null));
}
internal static class MethodBaseMethods
{
internal static readonly MethodInfo GetMethodFromHandle =
ReflectionHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle()));
internal static readonly MethodInfo GetMethodFromHandleWithDeclaringType =
ReflectionHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle(), new RuntimeTypeHandle()));
}
internal static class TypeMethods
{
internal static readonly MethodInfo GetTypeFromHandle =
ReflectionHelper.GetMethod(() => System.Type.GetTypeFromHandle(new RuntimeTypeHandle()));
}
}
}