定义核心接口契约

This commit is contained in:
zengwenjie
2025-09-15 14:07:45 +08:00
parent ac7e66efcf
commit 4d8a968551
9 changed files with 282 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public class DeedyElementCollection : ObservableCollection<IDeedyElement>
{
public DeedyElementCollection() : this(false) { }
public DeedyElementCollection(bool needDistinct = false)
{
this._needDistinct = needDistinct;
}
private bool _needDistinct = false;
public void AddRange(params IDeedyElement[] elements)
{
foreach (var element in elements) this.Add(element);
}
public void AddRange([AllowNull] IEnumerable<IDeedyElement> elements)
{
if (elements != null) foreach (var element in elements) this.Add(element);
}
public new void Add([AllowNull] IDeedyElement element)
{
if (element == null) return;
if (this._needDistinct)
{
foreach (var item in this.Items)
{
if (element.DEClass == item.DEClass && element.DETitle == item.DETitle) return;
}
}
base.Add(element);
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public abstract class DeedyAction : IDeedyAction
{
public string DEClass { get; protected internal set; } = "";
public string DETitle { get; set; } = "";
public string DERemark { get; set; } = "";
public string DEIdentify { get; set; } = "";
public IDeedyElement? DeedyParent { get; protected internal set; }
public IDeedyViewer? DeedyViewer { get; protected internal set; }
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// 发送属性变更通知
/// </summary>
/// <param name="propertyName">发生变更的属性</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary>
/// 读取一个字段的值
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
/// <returns>字段中的值</returns>
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
{
return field;
}
/// <summary>
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="value">字段的新值</param>
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
/// <returns>值是否有变更</returns>
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public static class DeedyHelper
{
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public class DeedyUIProxy : IDeedyVisual
{
private readonly IDeedyVisual _Visual;
public DeedyUIProxy(IDeedyVisual visual) { this._Visual = visual; }
public string DEClass { get; protected internal set; } = "";
public string DETitle { get; set; } = "";
public string DERemark { get; set; } = "";
public string DEIdentify { get; set; } = "";
public IDeedyElement? DeedyParent { get; protected internal set; }
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// 发送属性变更通知
/// </summary>
/// <param name="propertyName">发生变更的属性</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary>
/// 读取一个字段的值
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
/// <returns>字段中的值</returns>
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
{
//TODO这里处理内部属性获取逻辑包括运行时参数映射逻辑
return field;
}
/// <summary>
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="value">字段的新值</param>
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
/// <returns>值是否有变更</returns>
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
//TODO这里处理内部属性变更逻辑包括运行时参数映射逻辑
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}

View File

@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -44,11 +47,65 @@ namespace Deedy.Design
/// <MyNamespace:DeedyViewer/>
///
/// </summary>
public class DeedyViewer : Control
public class DeedyViewer : Control, IDeedyViewer
{
static DeedyViewer()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DeedyViewer), new FrameworkPropertyMetadata(typeof(DeedyViewer)));
}
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// 发送属性变更通知
/// </summary>
/// <param name="propertyName">发生变更的属性</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary>
/// 读取一个字段的值
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
/// <returns>字段中的值</returns>
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
{
return field;
}
/// <summary>
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
/// </summary>
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
/// <param name="value">字段的新值</param>
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
/// <returns>值是否有变更</returns>
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
[AllowNull, DefaultValue(null)]
/// <summary>
/// 动作节点
/// </summary>
public IDeedyAction DeedyAction
{
get { return (IDeedyAction)GetValue(DeedyActionProperty); }
set { SetValue(DeedyActionProperty, value); }
}
public static readonly DependencyProperty DeedyActionProperty =
DependencyProperty.Register("DeedyAction", typeof(IDeedyAction), typeof(DeedyViewer), new PropertyMetadata(null,
(d, e) => (d as DeedyViewer)?.DeedyAction_PropertyChangedCallback(d, e)));
/// <summary>
/// 处理「DeedyActionViewer.DeedyAction」属性变更
/// </summary>
protected virtual void DeedyAction_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public interface IDeedyAction : IDeedyElement
{
public IDeedyViewer? DeedyViewer { get; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public interface IDeedyElement : INotifyPropertyChanged
{
public string DEClass { get; }
public string DETitle { get; set; }
public string DERemark { get; set; }
public string DEIdentify { get; set; }
public IDeedyElement? DeedyParent { get; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public interface IDeedyViewer : INotifyPropertyChanged
{
[AllowNull]
public IDeedyAction DeedyAction { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Design
{
public interface IDeedyVisual : IDeedyElement
{
}
}