Skip to content

命令的分组与排序

默认情况下,命令的分组是其他

1670157000686-0fd3a84b-ec03-4b56-b489-a5d19eac552f.png

可以通过标注CategoryAttribute来自定义分组

csharp
    [Category("我的分组")]
    public class MyPluginCommand : Command
    {
    }

效果如下
1670156936640-c366cc92-c2cf-41e6-baea-311f9f6c39fe.png

如果分组名与既有的分组名一致,会加到已有的组里

csharp
    [Category("数据库")]
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

效果如下

1670157130025-a7f90da9-954d-4092-9fbc-89b5f6ccdecf.png

如果有多个插件,在同一分组,可以通过OrderWeightAttribute标注排序权重

csharp
    [OrderWeight(1)]
    [Category("我的分组")]
    public class MyPluginServerCommand1 : Command, ICommandExecutableInServerSideAsync
    {
        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }
    [OrderWeight(2)]
    [Category("我的分组")]
    public class MyPluginServerCommand2 : Command, ICommandExecutableInServerSideAsync
    {
        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }
    [OrderWeight(3)]
    [Category("我的分组")]
    public class MyPluginServerCommand3 : Command, ICommandExecutableInServerSideAsync
    {
        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

设计器效果
1670157329733-0f698335-3750-44c2-9364-11365cf9d409.png

更新: 2022-12-04 20:35:43
原文: https://www.yuque.com/robert-bh51n/ea8l6c/ptysbtfy0v9pngc0