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