Skip to content

Commit e753de6

Browse files
Made the methodinfo's static since they will not change.
1 parent 8fe11de commit e753de6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Core/Shared/CommandWrapper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace Community.VisualStudio.Toolkit.DependencyInjection.Core
1111
internal class CommandWrapper<T>
1212
where T : BaseDICommand
1313
{
14-
private readonly MethodInfo _beforeQueryStatusMethod = typeof(BaseDICommand).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).First(x => x.Name == "BeforeQueryStatus" && x.GetParameters().Count() == 2);
15-
private readonly MethodInfo _executeMethod = typeof(BaseDICommand).GetMethod("Execute", BindingFlags.Instance | BindingFlags.NonPublic);
16-
private readonly MethodInfo _executeAsyncMethod = typeof(BaseDICommand).GetMethod("ExecuteAsync", BindingFlags.Instance | BindingFlags.NonPublic);
14+
private static readonly MethodInfo _beforeQueryStatusMethod = typeof(BaseDICommand).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).First(x => x.Name == "BeforeQueryStatus" && x.GetParameters().Count() == 2);
15+
private static readonly MethodInfo _executeMethod = typeof(BaseDICommand).GetMethod("Execute", BindingFlags.Instance | BindingFlags.NonPublic);
16+
private static readonly MethodInfo _executeAsyncMethod = typeof(BaseDICommand).GetMethod("ExecuteAsync", BindingFlags.Instance | BindingFlags.NonPublic);
1717

1818
private readonly IServiceProvider _serviceProvider;
1919

@@ -48,22 +48,22 @@ public CommandWrapper(IServiceProvider serviceProvider, AsyncPackage package)
4848
protected void BeforeQueryStatus(object sender, EventArgs e)
4949
{
5050
using var scope = this._serviceProvider.CreateScope();
51-
var instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
51+
BaseDICommand instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
5252
_beforeQueryStatusMethod.Invoke(instance, new object[] { sender, e });
5353
}
5454

5555
protected void Execute(object sender, EventArgs e)
5656
{
5757
using var scope = this._serviceProvider.CreateScope();
58-
var instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
58+
BaseDICommand instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
5959
_executeMethod.Invoke(instance, new object[] { sender, e });
6060
}
6161

6262
protected async Task ExecuteAsync(OleMenuCmdEventArgs e)
6363
{
6464
using var scope = this._serviceProvider.CreateScope();
65-
var instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
66-
var executeAsyncTask = (Task)_executeAsyncMethod.Invoke(instance, new object[] { e });
65+
BaseDICommand instance = (BaseDICommand)scope.ServiceProvider.GetRequiredService(typeof(T));
66+
Task executeAsyncTask = (Task)_executeAsyncMethod.Invoke(instance, new object[] { e });
6767
await executeAsyncTask;
6868
}
6969
}

0 commit comments

Comments
 (0)