using System; using System.Runtime.Serialization; namespace WingCloudServer.GeneralDocTools.Model.Parameters { /// /// Range parameter base type /// /// Type of T [DataContract] public abstract class RangeParameterBase : IParameter where T : struct { private T _value; private T _initialValue; /// /// The value saved in setting file.Some times the value will be set but not saved to setting file. /// public T SavedValue { get; protected set; } /// /// value changed event /// public event EventHandler ValueChanged; /// /// Min value /// [DataMember] public T MinValue { get; set; } /// /// Max value /// [DataMember] public T MaxValue { get; set; } public T InitialValue => _initialValue; /// /// parameter value /// [DataMember] public T Value { get { return _value; } set { if (!Equals(_value, value)) { _value = value; OnValueChanged(); } } } /// /// parameter name /// public string Name { get; set; } /// /// parameter section /// public string Section { get; set; } /// /// parameter value changed state /// public bool IsChanged => !Equals(_initialValue, Value); /// /// notify value changed /// private void OnValueChanged() { ValueChanged?.Invoke(this, EventArgs.Empty); } /// /// change initial value /// public void ChangeInitialValue() { _initialValue = Value; SavedValue = Value; } public void ChangeSavedValue() { SavedValue = Value; } /// /// Set user value. /// /// user value. public abstract void ChangeParameterValue(object value); } /// /// Range long parameter. /// [DataContract] public class RangeLongParameter : RangeParameterBase { public override void ChangeParameterValue(object value) { var longParameter = value as LongParameter; if (longParameter != null) { Value = longParameter.Value; SavedValue = Value; } } } /// /// Range int parameter. /// [DataContract] public class RangeIntParameter : RangeParameterBase { public override void ChangeParameterValue(object value) { var intParameter = value as IntParameter; if (intParameter != null) { Value = intParameter.Value; SavedValue = Value; } } } }