编写部件组装逻辑(还差排序逻辑未完成)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -14,5 +14,16 @@ namespace Deedy.Activity
|
||||
[DebuggerDisplay("Count = {Count}")]
|
||||
public class ExpandoMapping : Dictionary<string, string>
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +127,43 @@ namespace Deedy.Activity
|
||||
return allow;
|
||||
}
|
||||
/// <summary>
|
||||
/// 将使用部件声明特性声明的动作部件与主体组装到一起并连接
|
||||
/// </summary>
|
||||
/// <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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 将一个元素插入到可变容器的指定位置
|
||||
/// </summary>
|
||||
/// <param name="this">可变元素容器</param>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user