已经完成带排序组装组合动作
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -129,37 +130,47 @@ namespace Deedy.Activity
|
||||
/// <summary>
|
||||
/// 将使用部件声明特性声明的动作部件与主体组装到一起并连接
|
||||
/// </summary>
|
||||
/// <param name="combined"></param>
|
||||
/// <param name="combined">要进行组装的组合元素</param>
|
||||
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);
|
||||
SortedList<int, IElement> sortedElements = new();
|
||||
Dictionary<string, PropertyInfo> properties = new();
|
||||
foreach (var prop in props)
|
||||
{
|
||||
if (prop.CanWrite && prop.CanRead)
|
||||
{
|
||||
if (!prop.CanRead || !prop.CanWrite) continue;
|
||||
if (!prop.PropertyType.IsAssignableFrom(typeof(IElement))) continue;
|
||||
var cpd = prop.GetCustomAttribute<CombinePartActionAttribute>();
|
||||
if (cpd == null) continue;
|
||||
var element = prop.GetValue(combined) as IElement;
|
||||
if (element == null) continue;
|
||||
|
||||
element.Help_SetAttachValue(CombinePartActionAttribute.CombinePartSign, prop.Name);
|
||||
sortedElements.Add(cpd.InitialSort, element);
|
||||
properties.Add(prop.Name, prop);
|
||||
}
|
||||
foreach (var partElement in sortedElements.Values)
|
||||
{
|
||||
string partSign = partElement.Help_GetAttachValue(CombinePartActionAttribute.CombinePartSign);
|
||||
if (string.IsNullOrEmpty(partSign)) continue;
|
||||
bool hasPart = false;
|
||||
foreach (var element in combined.Elements)
|
||||
{
|
||||
if (element.Help_GetAttachValue(CombinePartActionAttribute.CombinePartSign) == prop.Name)
|
||||
if (element.Help_GetAttachValue(CombinePartActionAttribute.CombinePartSign) == partSign)
|
||||
{
|
||||
element.LinkTo(combined);
|
||||
prop.SetValue(combined, element);
|
||||
properties[partSign].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);
|
||||
}
|
||||
if (partElement is IActionElement actionElement) actionElement.IsLocked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace Deedy.Activity
|
||||
combinedElement.Help_CombineElements();
|
||||
|
||||
this.LinkTo(element);
|
||||
if (this is IContainerElement container)
|
||||
foreach (IElement subElement in container.Elements)
|
||||
if (this is ICombinedElement combined)
|
||||
foreach (IElement subElement in combined.Elements)
|
||||
subElement.ReadyToWorking(this);
|
||||
}
|
||||
public virtual IElement? Clone()
|
||||
|
||||
Reference in New Issue
Block a user