ServiceProvider.GetService() 显示错误

ServiceProvider.GetService() showing error

我正在尝试创建一个扩展程序 (.vsix),我需要在其中访问 状态栏 并显示自定义文本。我正在关注 "Extend the status bar" 官方 Microsoft 文档。我放置代码的方式是:

private Command1(AsyncPackage package, OleMenuCommandService commandService)
{
     this.package = package ?? throw new ArgumentNullException(nameof(package));
     commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

     var menuCommandID = new CommandID(CommandSet, CommandId);
     var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);//calling spot
     commandService.AddCommand(menuItem);
}
private void MenuItemCallback(object sender, EventArgs e)
{
    //Error Line
    IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar));
    //Error Line

    // Make sure the status bar is not frozen
    int frozen;

    statusBar.IsFrozen(out frozen);

    if (frozen != 0)
    {
        statusBar.FreezeOutput(0);
    }

    // Set the status bar text and make its display static.
    statusBar.SetText("We just wrote to the status bar.");

    // Freeze the status bar.
    statusBar.FreezeOutput(1);

    // Get the status bar text.
    string text;
    statusBar.GetText(out text);
    System.Windows.Forms.MessageBox.Show(text);

    // Clear the status bar text.
    statusBar.FreezeOutput(0);
    statusBar.Clear();
}

虽然 运行 此代码在 GetService(typeof(SVsStatusbar)) 这部分显示错误。

错误是:

The type arguments for method 'ServiceExtensions.GetService(IServiceProvider, bool)' cannot be inferred from the usage. Try specifying the type arguments explicitly

我是不是做错了?我是 C# 的初学者。请考虑这一点。谢谢!

您需要一个服务提供商实例:

System.IServiceProvider serviceProvider = package as System.IServiceProvider;
statusBar = (IVsStatusbar)serviceProvider.GetService(typeof(SVsStatusbar));