Skip to content

字符串属性

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

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

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

在设计器中效果如下

1669595281576-606af2d4-ebc7-49ea-8c98-07d7228ad20f.png

如果需要更细致的控制,需要使用 TextPropertyAttribute 标注来控制
注意,标注TextPropertyAttribute的属性类型必须是 string

  1. 添加水印
    1. 设置TextPropertyAttribute 的 Watermark 属性
    2. 代码
csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        [TextProperty(Watermark = "请输入名称...")]
        public string MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }
3. 效果![1707124265526-b70d20fd-25c7-405d-b4b7-c90d58b9887e.png](./img/gn0E7kpN0yJMzo0c/1707124265526-b70d20fd-25c7-405d-b4b7-c90d58b9887e-661012.png)
4. 本特性要求活字格版本大于等于10.0.0.0
  1. 支持输入多行文本
    1. 设置TextPropertyAttribute 的 AcceptsReturn 属性
    2. 代码
csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        [TextProperty(AcceptsReturn = true)]
        public string MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }
3. 效果![1707124354482-db3f1737-d2cf-44f7-9b20-eaee8f50f81c.png](./img/gn0E7kpN0yJMzo0c/1707124354482-db3f1737-d2cf-44f7-9b20-eaee8f50f81c-163457.png)
4. 本特性要求活字格版本大于等于10.0.0.0
  1. 支持多语言功能
    1. 设置TextPropertyAttribute 的 CanSelectResource 属性
    2. 代码
csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        [TextProperty(CanSelectResource = true)]
        public string MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            // 通过代码 this.GetApplicationResource(MyProperty) 可以获取当前语言对应的值
            var strValue = GetApplicationResource(MyProperty);
            return new ExecuteResult()
            {
                Message = strValue,
            };
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

WARNING

this.GetApplicationResource(Key) 可以在多语言情况下把key替换为当前语言的字符串,在非多语言环境下,会返回原始的key字符串。

3. 效果![1707124426092-ce29ad29-078c-4d97-99b6-71f71338b852.png](./img/gn0E7kpN0yJMzo0c/1707124426092-ce29ad29-078c-4d97-99b6-71f71338b852-731119.png)
4. 本特性要求活字格版本大于等于10.0.0.0,并开启了多语言功能

更新: 2024-03-27 09:16:06
原文: https://www.yuque.com/robert-bh51n/ea8l6c/dw5doo7lle0uwcx3