Skip to content

高级单元格操作设计时支持

可以通过给单元格操作对应的方法添加 RunTimeMethodDesignerAttribute 来做一些设计时的细节控制

自定义参数校验

可以通过重写Validate方法自定义参数校验

代码:

csharp
    public class MyPluginCellType : CellType
    {
        [RunTimeMethod]
        [RunTimeMethodDesigner(typeof(MyRuntimeMethodDesigner))]
        public void MyOperation(bool param1 = true, bool param2 = false)
        {
        }
    }

    public class MyRuntimeMethodDesigner : RunTimeMethodDesigner
    {
        public override string Validate(IRuntimeMethodDesignerContext context)
        {
            if (!object.Equals(context.GetParameterValue("param1"), true) &&
                object.Equals(context.GetParameterValue("param2"), true))
            {
                return "param1 和 param2 必须至少勾选一个";
            }
            return base.Validate(context);
        }
    }

设计器效果

1707124901960-ebafdbbb-a008-49d5-8b67-f0745b7b6b47.png

属性动态隐藏显示

可以通过重写GetDesignerParameterVisible方法自定义参数校验

代码:

csharp
    public class MyPluginCellType : CellType
    {
        [RunTimeMethod]
        [RunTimeMethodDesigner(typeof(MyRuntimeMethodDesigner))]
        public void MyOperation(bool param1 = false, bool param2 = false)
        {
        }
    }

    public class MyRuntimeMethodDesigner : RunTimeMethodDesigner
    {
        public override bool GetDesignerParameterVisible(IRuntimeMethodDesignerContext context, string parameterName)
        {
            if (parameterName == "param2")
            {
                return object.Equals(context.GetParameterValue("param1"), true);
            }
            return base.GetDesignerParameterVisible(context, parameterName);
        }
    }

设计器效果1707125174362-34e1c372-eb3c-48da-9b3d-814a1c39ff3b.gif

WARNING

如果处理逻辑中需要依赖单元格,可以通过 context.Target 获取

更新: 2024-03-13 11:45:14
原文: https://www.yuque.com/robert-bh51n/ea8l6c/xolrcl4iyy2upbdl