67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
|
using Demo.Features;
|
||
|
using Demo.Primitives;
|
||
|
|
||
|
namespace Demo.Models;
|
||
|
|
||
|
public abstract class Chip : IMetadata
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 属性
|
||
|
/// </summary>
|
||
|
public MetadataPropertySet Properties { get; }
|
||
|
|
||
|
public string Name { get; set; }
|
||
|
|
||
|
public Version Version { get; set; } = new Version(0, 0, 0);
|
||
|
|
||
|
/// <summary>
|
||
|
/// 功能
|
||
|
/// </summary>
|
||
|
public virtual FeatureWrapper<Chip> Features { get; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// 公式
|
||
|
/// </summary>
|
||
|
public FormulaExecutor Formula { get; protected set; }
|
||
|
|
||
|
protected Chip(Chip? @base = null, bool needInherit = true)
|
||
|
{
|
||
|
if (needInherit)
|
||
|
{
|
||
|
Properties = @base?.Properties ?? new MetadataPropertySet();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Properties = new MetadataPropertySet();
|
||
|
}
|
||
|
Features = new FeatureWrapper<Chip>(this);
|
||
|
Formula = new FormulaExecutor(null, null);
|
||
|
Initialize();
|
||
|
}
|
||
|
|
||
|
public MetadataPropertySet.MetadataProperty? this[string name]
|
||
|
{
|
||
|
get => Properties.GetValue(name);
|
||
|
set => Properties.SetValue(name, value);
|
||
|
}
|
||
|
|
||
|
|
||
|
public Chip SetProperty(string name, object? value)
|
||
|
{
|
||
|
Properties.SetValue(name, value);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public TValue? GetProperty<TValue>(string name)
|
||
|
{
|
||
|
return Properties.GetValue(name).Cast<TValue>();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 初始化
|
||
|
/// </summary>
|
||
|
protected virtual void Initialize()
|
||
|
{
|
||
|
// var properties = this.GetType().GetProperties();
|
||
|
}
|
||
|
}
|