CommonUtils.Framework/Editor/demo.cs.txt

(完整代码) 1KB

using CodeGen.Commands.Global;
using CodeGen.Commands.IDE;
using CommonUtils;
using Microsoft;
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using System.Threading;
using Task = System.Threading.Tasks.Task;

namespace CodeGen
{
    [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
    [Guid("21234b1a-14a4-4722-89d8-7402fea12a52")]
    [ProvideMenuResource("Menus.ctmenu", 1)]
    public sealed class CodeGen : AsyncPackage
    {
        static readonly Guid _menuGroupId = new Guid("c66bb541-387c-4fbd-9be8-488ebd1f150e");
        static OleMenuCommandService _commandService;

        private static void AddMenuCommand(int id, EventHandler handler)
        => _commandService.AddCommand(new MenuCommand(handler, new CommandID(_menuGroupId, id)));

        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);

            _commandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
            Assumes.Present(_commandService);

            EditorUtil.SetServiceProvider(this);

            ///显示顺序是按照ID来的,跟添加顺序和ASCII顺序无关,ID随便写,但是要与vsct中统一
            //IDE
            AddMenuCommand(9001, Gen.Handler);
            //Global
            AddMenuCommand(9002, Home.Handler);

            "欢迎使用代码自动生成插件.".Print();
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。