using System; using System.ComponentModel; namespace SharpDX { // From SharpDX.Toolkit /// /// A lightweight Component base class. /// public abstract class ComponentBase : IComponent, INotifyPropertyChanged { /// /// Occurs while this component is disposing and before it is disposed. /// //internal event EventHandler Disposing; private string name; /// /// Gets or sets a value indicating whether the name of this instance is immutable. /// /// true if this instance is name immutable; otherwise, false. private readonly bool isNameImmutable; private object tag; /// /// Initializes a new instance of the class with a mutable name. /// protected ComponentBase() { } /// /// Initializes a new instance of the class with an immutable name. /// /// The name. protected ComponentBase(string name) { if (name != null) { this.name = name; this.isNameImmutable = true; } } /// /// Gets the name of this component. /// /// The name. [DefaultValue(null)] public string Name { get { return name; } set { if (isNameImmutable) throw new ArgumentException("Name property is immutable for this instance", "value"); if (name == value) return; name = value; OnPropertyChanged("Name"); } } /// /// Gets or sets the tag associated to this object. /// /// The tag. #if !W8CORE [Browsable(false)] #endif [DefaultValue(null)] public object Tag { get { return tag; } set { if (ReferenceEquals(tag, value)) return; tag = value; OnPropertyChanged("Tag"); } } /// /// Occurs when a property value changes. /// public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } }