Skip to content

Commit c951fa5

Browse files
Cache GetMethod call result as a static field.
1 parent 5b8eacb commit c951fa5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

LazyProxy/LazyProxyBuilder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public static class LazyProxyBuilder
2525
private static readonly ConcurrentDictionary<Type, Lazy<Type>> ProxyTypes =
2626
new ConcurrentDictionary<Type, Lazy<Type>>();
2727

28+
private static readonly MethodInfo CreateLazyMethod = typeof(LazyBuilder)
29+
.GetMethod("CreateInstance", BindingFlags.Public | BindingFlags.Static);
30+
2831
/// <summary>
2932
/// Defines at runtime a class that implements interface T
3033
/// and proxies all invocations to <see cref="Lazy{T}"/> of this interface.
@@ -170,10 +173,7 @@ private static TypeBuilder AddInitializeMethod(this TypeBuilder typeBuilder, Typ
170173
new [] { typeof(Func<object>) }
171174
);
172175

173-
// ReSharper disable once PossibleNullReferenceException
174-
var createLazyMethod = typeof(LazyBuilder)
175-
.GetMethod("CreateInstance", BindingFlags.Public | BindingFlags.Static)
176-
.MakeGenericMethod(type);
176+
var createLazyMethod = CreateLazyMethod.MakeGenericMethod(type);
177177

178178
var generator = methodBuilder.GetILGenerator();
179179

0 commit comments

Comments
 (0)