12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Runtime.Serialization;
- namespace WingCloudServer.GeneralDocTools.Model.Parameters
- {
- /// <summary>
- /// parameter base type
- /// </summary>
- /// <typeparam name="T"></typeparam>
- [DataContract]
- public abstract class ParameterBase<T> : IParameter
- {
- private T _initialValue;
- private T _value;
- /// <summary>
- /// The value saved in setting file.Some times the value will be set but not saved to setting file.
- /// </summary>
- public T SavedValue { get; private set; }
- /// <summary>
- /// parameter value
- /// </summary>
- [DataMember]
- public T Value
- {
- get
- {
- return _value;
- }
- set
- {
- if (!Equals(_value, value))
- {
- _value = value;
- OnValueChanged();
- }
- }
- }
- /// <summary>
- /// parameter name
- /// </summary>
- public string Name { get; set; } = string.Empty;
- /// <summary>
- /// parameter section
- /// </summary>
- public string Section { get; set; } = string.Empty;
- /// <summary>
- /// parameter value changed state
- /// </summary>
- public bool IsChanged => !Equals(_initialValue, Value);
- /// <summary>
- /// value changed event
- /// </summary>
- public event EventHandler ValueChanged;
- /// <summary>
- /// notify value changed
- /// </summary>
- private void OnValueChanged()
- {
- ValueChanged?.Invoke(this, EventArgs.Empty);
- }
- /// <summary>
- /// change initial value
- /// </summary>
- public void ChangeInitialValue()
- {
- _initialValue = Value;
- SavedValue = Value;
- }
- public void ChangeSavedValue()
- {
- SavedValue = Value;
- }
- public void ChangeParameterValue(object value)
- {
- var newParameter = value as ParameterBase<T>;
- if (newParameter != null)
- {
- Value = newParameter.Value;
- SavedValue = Value;
- }
- }
- }
- }
|