From 7fd0977d2d704f518641b9ae3cade9df30777633 Mon Sep 17 00:00:00 2001 From: zengwenjie <1663900244@qq.com> Date: Fri, 19 Sep 2025 18:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E9=83=A8=E4=BB=B6=E7=BB=84?= =?UTF-8?q?=E8=A3=85=E9=80=BB=E8=BE=91=EF=BC=88=E8=BF=98=E5=B7=AE=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E9=80=BB=E8=BE=91=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attribute/CombinePartActionAttribute.cs | 1 + .../Collection/ExpandoMapping.cs | 11 ++++++ .../Deedy.Activity/Helpers/ActionHelper.cs | 37 +++++++++++++++++++ .../Deedy.Activity/Helpers/ActivityHelper.cs | 11 ++++++ 4 files changed, 60 insertions(+) diff --git a/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs b/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs index ec6bb3a..f61f5f5 100644 --- a/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs +++ b/DeedyDesigner/Deedy.Activity/Attribute/CombinePartActionAttribute.cs @@ -10,6 +10,7 @@ namespace Deedy.Activity [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class CombinePartActionAttribute : Attribute, IInitialSortable { + public const string CombinePartSign = "CombinePartSign"; public CombinePartActionAttribute(int initSort) { this.InitialSort = initSort; } public int InitialSort { get; set; } = 0; diff --git a/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs b/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs index 21a8fcc..7140068 100644 --- a/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs +++ b/DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs @@ -14,5 +14,16 @@ namespace Deedy.Activity [DebuggerDisplay("Count = {Count}")] public class ExpandoMapping : Dictionary { + public ExpandoMapping() { } + public void SetValue(string key, string value) + { + if (this.ContainsKey(key)) this[key] = value; + else this.Add(key, value); + } + public string GetValue(string key) + { + if (!this.ContainsKey(key)) this.Add(key, string.Empty); + return this[key]; + } } } diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs index 6b2c272..49a2477 100644 --- a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs +++ b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs @@ -127,6 +127,43 @@ namespace Deedy.Activity return allow; } /// + /// 将使用部件声明特性声明的动作部件与主体组装到一起并连接 + /// + /// + public static void Help_CombineElements(this ICombinedElement combined) + { + if (combined == null) return; + if (combined.Elements == null) combined.Elements = []; + var props = combined.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField); + foreach (var prop in props) + { + if (prop.CanWrite && prop.CanRead) + { + if (!prop.PropertyType.IsAssignableFrom(typeof(IElement))) continue; + + bool hasPart = false; + foreach (var element in combined.Elements) + { + if (element.Help_GetAttachValue(CombinePartActionAttribute.CombinePartSign) == prop.Name) + { + element.LinkTo(combined); + prop.SetValue(combined, element); + hasPart = true; + break; + } + } + if (!hasPart) + { + IElement? partElement = prop.GetValue(combined) as IElement; + if (partElement == null) continue; + combined.Elements.Add(partElement); + partElement.LinkTo(combined); + partElement.Help_SetAttachValue(CombinePartActionAttribute.CombinePartSign, prop.Name); + } + } + } + } + /// /// 将一个元素插入到可变容器的指定位置 /// /// 可变元素容器 diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ActivityHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ActivityHelper.cs index 8a71ba9..fe0b9dd 100644 --- a/DeedyDesigner/Deedy.Activity/Helpers/ActivityHelper.cs +++ b/DeedyDesigner/Deedy.Activity/Helpers/ActivityHelper.cs @@ -9,5 +9,16 @@ namespace Deedy.Activity public static partial class Helper { //TODO:管理附加属性与准备方法 + public static string Help_GetAttachValue(this IActivity activity, string key) + { + if (activity == null || activity.ExpandoMapping == null) return string.Empty; + return activity.ExpandoMapping.GetValue(key); + } + public static void Help_SetAttachValue(this IActivity activity, string key, string value) + { + if (activity == null) return; + if (activity.ExpandoMapping == null) activity.ExpandoMapping = []; + activity.ExpandoMapping.SetValue(key, value); + } } }