using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using Newtonsoft.Json; namespace QuickModeling.Models { [JsonObject(MemberSerialization.OptIn)] public partial class ComponentConfig : ObservableValidator, ICloneable { private ComponentType componentType; private string description; private bool isEnabled = true; private string name; public object Clone() { var copy = (ComponentConfig)MemberwiseClone(); copy.Guid = Guid.NewGuid(); copy.Parameters = new ObservableCollection(Parameters.Select(p => p.Clone() as Parameter)); return copy; } [JsonProperty] public Guid Guid { get; set; } /// /// 配置名称 /// [Required(ErrorMessage = "配置名称不能为空")] [MinLength(1, ErrorMessage = "配置名称不能为空")] [JsonProperty] public string Name { get => name; set => SetProperty(ref name, value, true); } [JsonProperty] public ComponentType ComponentType { get => componentType; set => SetProperty(ref componentType, value); } /// /// 配置描述 /// [JsonProperty] public string Description { get => description; set => SetProperty(ref description, value); } [JsonProperty] public bool IsEnabled { get => isEnabled; set => SetProperty(ref isEnabled, value); } /// /// 参数 /// [JsonProperty] public ObservableCollection Parameters { get; set; } = new ObservableCollection(); } }