workFlow(一)Activity与自定义Activity显示样式的绑定

使用AttributeTableBuilder的AddCustomAttributes(Activity, Activity显示样式)

public class ActivitiesLibraryMetaData
    {
        public static void RegisterAll()
        {
            var builder = new AttributeTableBuilder();

            //微软自带活动属性翻译
            builder.AddCustomAttributes(typeof(Activity), typeof(Activity).GetProperty("DisplayName"), new DisplayNameAttribute("名称"));
            builder.AddCustomAttributes(typeof(Activity), typeof(Activity).GetProperty("DisplayName"),  new EditorAttribute(typeof(DisplayNameEditor), typeof(PropertyValueEditor)));


            builder.AddCustomAttributes(typeof(ActivityBuilder), typeof(ActivityBuilder).GetProperty("Name"), new DisplayNameAttribute("名称"));
            builder.AddCustomAttributes(typeof(ActivityBuilder), typeof(ActivityBuilder).GetProperty("Name"), new EditorAttribute(typeof(DisplayNameEditor), typeof(PropertyValueEditor)));

            //循环
            builder.AddCustomAttributes(typeof(DoWhile), typeof(DoWhile).GetProperty("Condition"), new DisplayNameAttribute("条件"));
            builder.AddCustomAttributes(typeof(While), typeof(While).GetProperty("Condition"), new DisplayNameAttribute("条件"));
            //builder.AddCustomAttributes(typeof(ForEach<>), typeof(ForEach<>).GetProperty("TypeArgument"), new DisplayNameAttribute("类型"));
            builder.AddCustomAttributes(typeof(ForEach<>), typeof(ForEach<>).GetProperty("Values"), new DisplayNameAttribute("值数组"));

            //判断
            builder.AddCustomAttributes(typeof(If), typeof(If).GetProperty("Condition"), new DisplayNameAttribute("条件"));
            builder.AddCustomAttributes(typeof(Switch<>), typeof(Switch<>).GetProperty("Expression"), new DisplayNameAttribute("表达式"));

            //并行
            builder.AddCustomAttributes(typeof(Parallel), typeof(Parallel).GetProperty("CompletionCondition"), new DisplayNameAttribute("完成条件"));
            builder.AddCustomAttributes(typeof(ParallelForEach<>), typeof(ParallelForEach<>).GetProperty("CompletionCondition"), new DisplayNameAttribute("完成条件"));
            //builder.AddCustomAttributes(typeof(ParallelForEach<>), typeof(ParallelForEachWithBodyFactory<>).GetProperty("TypeArgument"), new DisplayNameAttribute("类型"));
            builder.AddCustomAttributes(typeof(ParallelForEach<>), typeof(ParallelForEach<>).GetProperty("Values"), new DisplayNameAttribute("值数组"));

            //选择
            builder.AddCustomAttributes(typeof(PickBranch), typeof(PickBranch).GetProperty("DisplayName"), new DisplayNameAttribute("名称"));

            //基元
            builder.AddCustomAttributes(typeof(Assign), typeof(Assign).GetProperty("To"), new DisplayNameAttribute("变量"));
            builder.AddCustomAttributes(typeof(Assign), typeof(Assign).GetProperty("Value"), new DisplayNameAttribute("值"));
            builder.AddCustomAttributes(typeof(Delay), typeof(Delay).GetProperty("Duration"), new DisplayNameAttribute("时间间隔"));
            builder.AddCustomAttributes(typeof(WriteLine), typeof(WriteLine).GetProperty("Text"), new DisplayNameAttribute("文本"));
            builder.AddCustomAttributes(typeof(WriteLine), typeof(WriteLine).GetProperty("TextWriter"), new DisplayNameAttribute("文本写入器"));
          
            //流程图
            builder.AddCustomAttributes(typeof(Flowchart), typeof(Flowchart).GetProperty("Nodes"),new DisplayNameAttribute("节点集合"));
            
            
            builder.AddCustomAttributes(typeof(FlowDecision), typeof(FlowDecision).GetProperty("Condition"), new DisplayNameAttribute("条件"));


            builder.AddCustomAttributes(typeof(FlowDecision), typeof(FlowDecision).GetProperty("Condition"), new DisplayNameAttribute("条件"));
            
            builder.AddCustomAttributes(typeof(FlowSwitch<>), typeof(FlowSwitch<>).GetProperty("Expression"), new DisplayNameAttribute("表达式"));
			
			//自定义一个ExcelScope类继承NativeActivity
			//ExcelScopeDesigner 为WPF的界面设计
			//将ExcelScope与 ExcelScopeDesigner 关联
            builder.AddCustomAttributes(typeof(ExcelScope), new DesignerAttribute(typeof(ExcelScopeDesigner)));
        }

        /// <summary>
        /// 
        /// </summary>
        public void Register()
        {
            RegisterAll();
        }
    }
发布了62 篇原创文章 · 获赞 28 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/native_lee/article/details/89492612