using System; using System.Collections.Generic; using System.Linq; namespace CadParamPluging.Common { [Serializable] public class ParamDefinition { public string Key { get; set; } public string Label { get; set; } public ParamValueType Type { get; set; } public bool Required { get; set; } /// /// Free-form note, typically the original "填写方式". /// public string Hint { get; set; } /// /// Stored as string for XML friendliness. /// public string DefaultValue { get; set; } /// /// Numeric constraints stored as string for XML friendliness. /// public string Min { get; set; } public string Max { get; set; } public List EnumOptions { get; set; } public string Group { get; set; } public int Order { get; set; } public ParamDefinition() { EnumOptions = new List(); } public ParamDefinition Clone() { return new ParamDefinition { Key = Key, Label = Label, Type = Type, Required = Required, Hint = Hint, DefaultValue = DefaultValue, Min = Min, Max = Max, EnumOptions = (EnumOptions ?? new List()).ToList(), Group = Group, Order = Order }; } public void Normalize() { Key = (Key ?? string.Empty).Trim(); Label = (Label ?? string.Empty).Trim(); Hint = (Hint ?? string.Empty).Trim(); DefaultValue = (DefaultValue ?? string.Empty).Trim(); Min = (Min ?? string.Empty).Trim(); Max = (Max ?? string.Empty).Trim(); Group = (Group ?? string.Empty).Trim(); if (EnumOptions != null) { EnumOptions = EnumOptions .Where(s => !string.IsNullOrWhiteSpace(s)) .Select(s => s.Trim()) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } else { EnumOptions = new List(); } } } }