using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Xml.Serialization; namespace RainmeterStudio.Core.Model { public interface IProperty : INotifyPropertyChanged { /// /// Gets the name of the property /// string Name { get; } /// /// Gets or sets the value of the property /// object Value { get; set; } /// /// Gets the data type of the property /// Type Type { get; } /// /// Gets the children of this property /// ObservableCollection Children { get; } } /// /// Represents a property /// public class Property : IProperty { #region Name property /// /// Gets the name of the property /// public virtual string Name { get; private set; } #endregion #region Value property private object _value; /// /// Gets or sets the value of the property /// public virtual object Value { get { return _value; } set { // Test if type changed bool typeChanged = (_value.GetType() != value.GetType()); // Set value _value = value; // Trigger event if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Value")); if (typeChanged) PropertyChanged(this, new PropertyChangedEventArgs("Type")); } } } #endregion #region Type property /// /// Gets the type of the property /// public virtual Type Type { get { return Value.GetType(); } } #endregion #region Children property /// /// Gets the children of this property /// public ObservableCollection Children { get; private set; } #endregion #region Property changed event /// /// Triggered when a property changes /// public virtual event PropertyChangedEventHandler PropertyChanged; #endregion #region Constructors /// /// Initializes this property /// /// Name of the property public Property(string name) { Name = name; Value = null; Children = new ObservableCollection(); } /// /// Initializes this property /// /// Name of the property /// Value of the property public Property(string name, object value) { Name = name; Value = value; Children = new ObservableCollection(); } #endregion } namespace Generic { /// /// Generic property /// /// Type of property public class Property : IProperty { #region Value property private T _value; /// /// Gets or sets the value of this property /// public T Value { get { return _value; } set { // Set value _value = value; // Trigger event if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Value")); } } /// /// Gets or sets the value of this property. Overriden from the generic property. /// /// Thrown if value is not of the right type. object IProperty.Value { get { return _value; } set { this.Value = (T)value; } } #endregion #region Type property /// /// Gets the type of this property /// public Type Type { get { return typeof(T); } } #endregion #region Property changed event /// /// Triggered when a property changes /// public event PropertyChangedEventHandler PropertyChanged; #endregion #region Constructors /// /// Initializes this property /// /// Name of the property public Property(string name) { Name = name; Value = default(T); Children = new ObservableCollection(); } /// /// Initializes this property /// /// Name of the property /// Value of the property public Property(string name, T value) { Name = name; Value = value; Children = new ObservableCollection(); } #endregion /// /// Gets the name of the property /// public string Name { get; private set; } /// /// Gets the children of this property /// public ObservableCollection Children { get; private set; } } } }