using System; namespace Aitex.Core.RT.SCCore { public class SCConfigItem { public event EventHandler OnValueChanged; public string Name { get; set; } public string Path { get; set; } public string Default { get; set; } public string Min { get; set; } public string Max { get; set; } public string Unit { get; set; } public string Type { get; set; } public string Tag { get; set; } public string Parameter { get; set; } public string Description { get; set; } public object Value => Type switch { "Bool" => BoolValue, "Double" => DoubleValue, "String" => StringValue, "Integer" => IntValue, _ => null, }; public Type Typeof => Type switch { "Bool" => typeof(bool), "Double" => typeof(double), "String" => typeof(string), "Integer" => typeof(int), _ => null, }; public string PathName => string.IsNullOrEmpty(Path) ? Name : (Path + "." + Name); public int IntValue { get; set; } public double DoubleValue { get; set; } public bool BoolValue { get; set; } public string StringValue { get; set; } public bool SetValue(object value) { var isChanged = false; switch (Type) { case "Bool": { var bValue = (bool)value; if (bValue != BoolValue) { BoolValue = bValue; isChanged = true; } break; } case "Integer": { var intValue = (int)value; if (intValue != IntValue) { IntValue = intValue; isChanged = true; } break; } case "Double": { var dblValue = (double)value; if (Math.Abs(dblValue - DoubleValue) > 0.0001) { DoubleValue = dblValue; isChanged = true; } break; } case "String": { var strValue = (string)value; if (strValue != StringValue) { StringValue = strValue; isChanged = true; } break; } } return isChanged; } public SCConfigItem Clone() { return new SCConfigItem { Name = Name, Path = Path, Default = Default, Min = Min, Max = Max, Unit = Unit, Type = Type, Tag = Tag, Parameter = Parameter, Description = Description, StringValue = StringValue, IntValue = IntValue, DoubleValue = DoubleValue, BoolValue = BoolValue }; } } }