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