页面树结构
转至元数据结尾
转至元数据起始

默认情况下,如果一个属性的类型是 bool 那么这个属性会被自动识别为整数属性,不需要做任何额外的事情

    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        public bool MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }


在设计器中效果如下:

如果需要更细致的控制,需要使用BoolPropertyAttribute标注来控制。

注意:标注BoolPropertyAttribute的属性类型必须是 bool。

  1. Bool属性生成的复选框在不同场景下需要控制不同缩进级别,使得在多个属性直接看起来更有层次结构
    1.   可以设置BoolProperty 的 IndentLevel 属性控制缩进等级
    2. 代码

          public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
          {
              [BoolProperty(IndentLevel = 0)]
              public bool MyProperty1 { get; set; }
      
              [BoolProperty(IndentLevel = 1)]
              public bool MyProperty2 { get; set; }
      
              [BoolProperty(IndentLevel = 2)]
              public bool MyProperty3 { get; set; }
      
              public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
              {
                  return new ExecuteResult();
              }
              public override CommandScope GetCommandScope()
              {
                  return CommandScope.ExecutableInServer;
              }
          }


    3. 效果
    4. 其他说明

      如果标注了 BoolProperty 属性,但是没有设置缩进等级,则默认缩进等级为 0

    注意:

    如果Bool属性的默认值是 True,必须要添加DefaultValue标注,否则会出现属性无法保存的问题。

        public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
        {
            [DefaultValue(true)]
            public bool MyProperty { get; set; } = true;
    
            public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
            {
                return new ExecuteResult();
            }
            public override CommandScope GetCommandScope()
            {
                return CommandScope.ExecutableInServer;
            }
        }


  • 无标签