No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

102 líneas
2.8 KiB

  1. using System;
  2. using System.ComponentModel;
  3. namespace SharpDX
  4. {
  5. // From SharpDX.Toolkit
  6. /// <summary>
  7. /// A lightweight Component base class.
  8. /// </summary>
  9. public abstract class ComponentBase : IComponent, INotifyPropertyChanged
  10. {
  11. /// <summary>
  12. /// Occurs while this component is disposing and before it is disposed.
  13. /// </summary>
  14. //internal event EventHandler<EventArgs> Disposing;
  15. private string name;
  16. /// <summary>
  17. /// Gets or sets a value indicating whether the name of this instance is immutable.
  18. /// </summary>
  19. /// <value><c>true</c> if this instance is name immutable; otherwise, <c>false</c>.</value>
  20. private readonly bool isNameImmutable;
  21. private object tag;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="ComponentBase" /> class with a mutable name.
  24. /// </summary>
  25. protected ComponentBase()
  26. {
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="ComponentBase" /> class with an immutable name.
  30. /// </summary>
  31. /// <param name="name">The name.</param>
  32. protected ComponentBase(string name)
  33. {
  34. if (name != null)
  35. {
  36. this.name = name;
  37. this.isNameImmutable = true;
  38. }
  39. }
  40. /// <summary>
  41. /// Gets the name of this component.
  42. /// </summary>
  43. /// <value>The name.</value>
  44. [DefaultValue(null)]
  45. public string Name
  46. {
  47. get { return name; }
  48. set
  49. {
  50. if (isNameImmutable)
  51. throw new ArgumentException("Name property is immutable for this instance", "value");
  52. if (name == value) return;
  53. name = value;
  54. OnPropertyChanged("Name");
  55. }
  56. }
  57. /// <summary>
  58. /// Gets or sets the tag associated to this object.
  59. /// </summary>
  60. /// <value>The tag.</value>
  61. #if !W8CORE
  62. [Browsable(false)]
  63. #endif
  64. [DefaultValue(null)]
  65. public object Tag
  66. {
  67. get
  68. {
  69. return tag;
  70. }
  71. set
  72. {
  73. if (ReferenceEquals(tag, value)) return;
  74. tag = value;
  75. OnPropertyChanged("Tag");
  76. }
  77. }
  78. /// <summary>
  79. /// Occurs when a property value changes.
  80. /// </summary>
  81. public event PropertyChangedEventHandler PropertyChanged;
  82. protected virtual void OnPropertyChanged(string propertyName)
  83. {
  84. PropertyChangedEventHandler handler = PropertyChanged;
  85. if (handler != null)
  86. {
  87. handler(this, new PropertyChangedEventArgs(propertyName));
  88. }
  89. }
  90. }
  91. }