编写私有属性设置辅助器
This commit is contained in:
		@@ -31,6 +31,7 @@ namespace Deedy.Activity
 | 
			
		||||
    {
 | 
			
		||||
        public static double IndentRuler { get; set; } = 30;
 | 
			
		||||
 | 
			
		||||
        public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
 | 
			
		||||
 | 
			
		||||
        public const string PART_ItemsContainer = "PART_ItemsContainer";
 | 
			
		||||
        public const string PART_TitleContainer = "PART_TitleContainer";
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
 | 
			
		||||
    public class CombinePartActionAttribute : Attribute
 | 
			
		||||
    {
 | 
			
		||||
        public CombinePartActionAttribute(int sort) { this.Sort = sort; }
 | 
			
		||||
        public int Sort { get; private set; }
 | 
			
		||||
        public void Binding(object target, PropertyInfo property)
 | 
			
		||||
        {
 | 
			
		||||
            if (!property.CanRead || !property.CanWrite) throw new ArgumentException("绑定为组装部件的属性必须具备写访问器...");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -10,11 +10,13 @@ namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    public abstract class BasalAction : IActionElement
 | 
			
		||||
    {
 | 
			
		||||
        public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
 | 
			
		||||
 | 
			
		||||
        protected internal BasalAction() { }
 | 
			
		||||
        public string DEClass { get; protected internal set; } = "";
 | 
			
		||||
        public string DETitle { get; set; } = "";
 | 
			
		||||
        public string DERemark { get; set; } = "";
 | 
			
		||||
        public string DEIdentify { get; set; } = "";
 | 
			
		||||
        public string Class { get; protected internal set; } = "";
 | 
			
		||||
        public string Title { get; set; } = "";
 | 
			
		||||
        public string Remark { get; set; } = "";
 | 
			
		||||
        public string Identify { get; set; } = "";
 | 
			
		||||
        public int DepthLevel { get; protected internal set; } = 0;
 | 
			
		||||
        public bool IsLockedElement { get; set; } = false;
 | 
			
		||||
        protected internal LogInfo _InstantInfo = LogInfo.Empty;
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ namespace Deedy.Activity
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var item in this.Items)
 | 
			
		||||
                {
 | 
			
		||||
                    if (element.DEClass == item.DEClass && element.DETitle == item.DETitle) return;
 | 
			
		||||
                    if (element.Class == item.Class && element.Title == item.Title) return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            base.Add(element);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								DeedyDesigner/Deedy.Activity/Collection/ExpandoMapping.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 用于扩展一个对象的非必要属性
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ExpandoMapping : Dictionary<string, string>
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7,6 +7,9 @@ using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 组合元素:内部由多个元素组合而成,但不允许修改内部元素的组合逻辑
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public interface ICombinedElement : IElement
 | 
			
		||||
    {
 | 
			
		||||
        public ElementCollection Elements { get; set; }
 | 
			
		||||
 
 | 
			
		||||
@@ -8,5 +8,7 @@ namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    public sealed class Runtime
 | 
			
		||||
    {
 | 
			
		||||
        public Runtime() { }
 | 
			
		||||
        public WorkMode WorkMode { get; internal set; } = WorkMode.Waiting;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,10 +10,12 @@ namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    public class DeedyLayout : IDeedyLayout
 | 
			
		||||
    {
 | 
			
		||||
        public string DEClass { get; protected internal set; } = "";
 | 
			
		||||
        public string DETitle { get; set; } = "";
 | 
			
		||||
        public string DERemark { get; set; } = "";
 | 
			
		||||
        public string DEIdentify { get; set; } = "";
 | 
			
		||||
        public ExpandoMapping ExpandoMapping { get; set; } = new ExpandoMapping();
 | 
			
		||||
        public DeedyLayout() { }
 | 
			
		||||
        public string Class { get; protected internal set; } = "";
 | 
			
		||||
        public string Title { get; set; } = "";
 | 
			
		||||
        public string Remark { get; set; } = "";
 | 
			
		||||
        public string Identify { get; set; } = "";
 | 
			
		||||
        public int DepthLevel { get; protected internal set; } = 0;
 | 
			
		||||
        public IElement? ParentElement { get; protected internal set; }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Runtime.CompilerServices;
 | 
			
		||||
 | 
			
		||||
namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
@@ -212,6 +213,10 @@ namespace Deedy.Activity
 | 
			
		||||
 | 
			
		||||
            return default;
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 调整子节点的退出线位置
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="container">要调整的带退出线容器</param>
 | 
			
		||||
        public static void AdjustExitlinePosition(this IContainerWithExitline container)
 | 
			
		||||
        {
 | 
			
		||||
            if (container != null
 | 
			
		||||
@@ -237,9 +242,62 @@ namespace Deedy.Activity
 | 
			
		||||
                        if (container.ExitlinePosition == ExitlinePosition.Rightlower)
 | 
			
		||||
                            lastChild.ExitlinePosition = ExitlinePosition.Rightlower;
 | 
			
		||||
                    }
 | 
			
		||||
                    //lastChild.AdjustExitlinePosition();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 设置「IElement」对象的「DepthLevel」属性值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="element">要设置的对象</param>
 | 
			
		||||
        /// <param name="depthLevel">层级深度</param>
 | 
			
		||||
        /// <returns>如果设置失败则返回「False」</returns>
 | 
			
		||||
        public static bool Setter_DepthLevel(this IElement element, int depthLevel)
 | 
			
		||||
        {
 | 
			
		||||
            if (element is BasalAction action)
 | 
			
		||||
            {
 | 
			
		||||
                ActionSetter_DepthLevel(action, depthLevel);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    element.SetNamedPropertyValue(nameof(IElement.DepthLevel), depthLevel);
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                catch { return false; }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_DepthLevel")]
 | 
			
		||||
        private static extern void ActionSetter_DepthLevel(BasalAction action, int value);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 设置「IElement」对象的「ParentElement」属性值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="element">要设置的对象</param>
 | 
			
		||||
        /// <param name="parent">属性值</param>
 | 
			
		||||
        /// <returns>如果设置失败则返回「False」</returns>
 | 
			
		||||
        public static bool Setter_ParentElement(this IElement element, IElement? parent)
 | 
			
		||||
        {
 | 
			
		||||
            if (element is BasalAction action)
 | 
			
		||||
            {
 | 
			
		||||
                ActionSetter_ParentElement(action, parent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    element.SetNamedPropertyValue(nameof(IElement.ParentElement), parent);
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                catch
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "set_ParentElement")]
 | 
			
		||||
        private static extern void ActionSetter_ParentElement(BasalAction action, IElement? value);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,6 @@ namespace Deedy.Activity
 | 
			
		||||
        [AllowNull]
 | 
			
		||||
        public LogInfoCollection LogInfos { get; }
 | 
			
		||||
        public ViewerState ViewerState { get; }
 | 
			
		||||
        public WorkMode WorkMode { get; }
 | 
			
		||||
        public Brush FillBrush { get; set; }
 | 
			
		||||
        public Brush StrokeBrush { get; set; }
 | 
			
		||||
        public double StrokeThickness { get; set; }
 | 
			
		||||
 
 | 
			
		||||
@@ -12,5 +12,7 @@ namespace Deedy.Activity
 | 
			
		||||
        public void ReadyToWorking(IElement? element = null, Output? output = null);
 | 
			
		||||
        public void ReadyToEditing(Runtime runtime);
 | 
			
		||||
        public void ReadyToRunning(Runtime runtime);
 | 
			
		||||
        public WorkMode WorkMode => Runtime?.WorkMode ?? WorkMode.Waiting;
 | 
			
		||||
        public ExpandoMapping ExpandoMapping { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,10 +12,10 @@ namespace Deedy.Activity
 | 
			
		||||
{
 | 
			
		||||
    public interface IElement : IActivity, INotifyPropertyChanged
 | 
			
		||||
    {
 | 
			
		||||
        public string DEClass { get; }
 | 
			
		||||
        public string DETitle { get; set; }
 | 
			
		||||
        public string DERemark { get; set; }
 | 
			
		||||
        public string DEIdentify { get; set; }
 | 
			
		||||
        public string Class { get; }
 | 
			
		||||
        public string Title { get; set; }
 | 
			
		||||
        public string Remark { get; set; }
 | 
			
		||||
        public string Identify { get; set; }
 | 
			
		||||
        public int DepthLevel { get; }
 | 
			
		||||
        public IElement? ParentElement { get; }
 | 
			
		||||
        public IElement RootElement { get; }
 | 
			
		||||
@@ -39,15 +39,18 @@ namespace Deedy.Activity
 | 
			
		||||
                    {
 | 
			
		||||
                        container.Remove(this);
 | 
			
		||||
                        container.Append(this);
 | 
			
		||||
                        this.SetNamedPropertyValue(nameof(ParentElement), element);
 | 
			
		||||
                        //this.SetNamedPropertyValue(nameof(ParentElement), element);
 | 
			
		||||
                        this.Setter_ParentElement(element);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                this.SetNamedPropertyValue(nameof(ParentElement), element);
 | 
			
		||||
                //this.SetNamedPropertyValue(nameof(ParentElement), element);
 | 
			
		||||
                this.Setter_ParentElement(element);
 | 
			
		||||
            }
 | 
			
		||||
            this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1);
 | 
			
		||||
            //this.SetNamedPropertyValue(nameof(DepthLevel), (this.ParentElement?.DepthLevel ?? 0) + 1);
 | 
			
		||||
            this.Setter_DepthLevel((this.ParentElement?.DepthLevel ?? 0) + 1);
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 断开自身与父级节点的链接关系
 | 
			
		||||
@@ -55,8 +58,10 @@ namespace Deedy.Activity
 | 
			
		||||
        public virtual void Unlink()
 | 
			
		||||
        {
 | 
			
		||||
            (this.ParentElement as IContainerElement)?.Remove(this);
 | 
			
		||||
            this.SetNamedPropertyValue<IElement?>(nameof(ParentElement), null);
 | 
			
		||||
            this.SetNamedPropertyValue(nameof(DepthLevel), 0);
 | 
			
		||||
            //this.SetNamedPropertyValue<IElement?>(nameof(ParentElement), null);
 | 
			
		||||
            this.Setter_ParentElement(null);
 | 
			
		||||
            //this.SetNamedPropertyValue(nameof(DepthLevel), 0);
 | 
			
		||||
            this.Setter_DepthLevel(0);
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 构建结构树,设置层级:并且完成参数映射的刷新
 | 
			
		||||
 
 | 
			
		||||
@@ -8,4 +8,8 @@
 | 
			
		||||
    <UseWPF>true</UseWPF>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ProjectReference Include="..\Deedy.Activity\Deedy.Activity.csproj" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user