完成参数映射及参数组的构建
This commit is contained in:
		@@ -1,20 +1,64 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.ComponentModel;
 | 
				
			||||||
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Reflection;
 | 
				
			||||||
 | 
					using System.Runtime.CompilerServices;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Deedy.Activity
 | 
					namespace Deedy.Activity
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
 | 
					    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
 | 
				
			||||||
    public class ParamDefineAttribute : Attribute, IInitialSortable
 | 
					    public class ParamDefineAttribute : Attribute, IInitialSortable, INotifyPropertyChanged
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public int InitialSort { get; set; } = 0;
 | 
					 | 
				
			||||||
        public ParamDefineAttribute() { }
 | 
					        public ParamDefineAttribute() { }
 | 
				
			||||||
 | 
					        public event PropertyChangedEventHandler? PropertyChanged;
 | 
				
			||||||
 | 
					        #region 定义属性通知事件相关方法
 | 
				
			||||||
 | 
					        //public event PropertyChangedEventHandler? PropertyChanged;
 | 
				
			||||||
 | 
					        protected virtual void OnPropertyChanged([CallerMemberName, AllowNull] string propertyName = null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        protected virtual T GetField<T>(ref T field, [CallerMemberName, AllowNull] string propertyName = null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return field;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName, AllowNull] string propertyName = null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
 | 
				
			||||||
 | 
					            field = value;
 | 
				
			||||||
 | 
					            OnPropertyChanged(propertyName);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public int InitialSort { get; set; } = 0;
 | 
				
			||||||
 | 
					        public ParamDefineAttribute(string title, string remark, string @default) { }
 | 
				
			||||||
 | 
					        public string Name { get; set; } = "";
 | 
				
			||||||
        public string Title { get; set; } = "参数名称";
 | 
					        public string Title { get; set; } = "参数名称";
 | 
				
			||||||
        public string Remark { get; set; } = "参数描述";
 | 
					        public string Remark { get; set; } = "参数描述";
 | 
				
			||||||
 | 
					        public string Identify { get; set; } = "";
 | 
				
			||||||
        public string Default { get; set; } = "";
 | 
					        public string Default { get; set; } = "";
 | 
				
			||||||
        public string DesignValue { get; set; } = "";
 | 
					        protected internal string _DesignValue = "";
 | 
				
			||||||
        public string GroupName { get; set; } = "";
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 设计期值
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public string DesignValue
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            get { return GetField<string>(ref _DesignValue); }
 | 
				
			||||||
 | 
					            set
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (SetField<string>(ref _DesignValue, value))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    // 这里可以加入属性变更后的处理逻辑
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public string GroupName { get; set; } = ParamGroupAttribute.DefaultParams;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public object? Target { get; protected internal set; }
 | 
				
			||||||
 | 
					        public PropertyInfo? Property { get; protected internal set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 | 
				
			|||||||
using System.Collections.ObjectModel;
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
using System.Collections.Specialized;
 | 
					using System.Collections.Specialized;
 | 
				
			||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
@@ -16,5 +17,23 @@ namespace Deedy.Activity
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly SortedList<int, ParamDefineAttribute> _SoredList = new();
 | 
					        private readonly SortedList<int, ParamDefineAttribute> _SoredList = new();
 | 
				
			||||||
        internal ParamDefineCollection() { }
 | 
					        internal ParamDefineCollection() { }
 | 
				
			||||||
 | 
					        public bool TryGetParamDefine(string name, [NotNull] out ParamDefineAttribute value)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ParamDefineAttribute pda = new();
 | 
				
			||||||
 | 
					            bool result = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            foreach (var item in this)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (item.Name == name)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    pda = item;
 | 
				
			||||||
 | 
					                    result = true;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            value = pda;
 | 
				
			||||||
 | 
					            return result;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Reflection;
 | 
				
			||||||
using System.Runtime.CompilerServices;
 | 
					using System.Runtime.CompilerServices;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
@@ -98,9 +99,24 @@ namespace Deedy.Activity
 | 
				
			|||||||
        /// <param name="output">消息输出器</param>
 | 
					        /// <param name="output">消息输出器</param>
 | 
				
			||||||
        public static void Help_BuildParamMapping(this IElement element, Output? output = null)
 | 
					        public static void Help_BuildParamMapping(this IElement element, Output? output = null)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            //TODO:构建元素的参数映射表
 | 
					 | 
				
			||||||
            if (element == null) return;
 | 
					            if (element == null) return;
 | 
				
			||||||
            if (element.ParamsMapping == null) element.ParamsMapping = new();
 | 
					            if (element.ParamsMapping == null) element.ParamsMapping = new();
 | 
				
			||||||
 | 
					            var props = element.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
 | 
				
			||||||
 | 
					            foreach (var prop in props)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (prop.CanWrite && prop.CanRead)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var pda = prop.GetCustomAttribute<ParamDefineAttribute>();
 | 
				
			||||||
 | 
					                    if (pda != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        pda.Name = prop.Name;
 | 
				
			||||||
 | 
					                        if (element.ParamsMapping.TryGetParamDefine(prop.Name, out var value)) pda = value;
 | 
				
			||||||
 | 
					                        else element.ParamsMapping.Add(pda);
 | 
				
			||||||
 | 
					                        value.Target = element;
 | 
				
			||||||
 | 
					                        value.Property = prop;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// 构建一个元素的参数分组,为设计器准备的辅助方法
 | 
					        /// 构建一个元素的参数分组,为设计器准备的辅助方法
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user