using System.ComponentModel; namespace Vanara.Windows.Shell; /// /// /// /// /// /// public abstract class ComObjWrapper : IDisposable, IEquatable, INotifyPropertyChanged where TObj : ComObjWrapper where TComType : class { /// The internal reference to the COM object. protected TComType iObj; /// Initializes a new instance of the class. /// The base interface. protected ComObjWrapper(TComType baseInterface) => iObj = baseInterface ?? throw new ArgumentNullException(nameof(baseInterface)); /// Occurs when a property value changes. public virtual event PropertyChangedEventHandler? PropertyChanged; /// Gets the COM interface supporting this type. /// The COM interface. public virtual TComType ComInterface => iObj; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public virtual void Dispose() { } /// Determines whether the specified , is equal to this instance. /// The to compare with this instance. /// if the specified is equal to this instance; otherwise, . public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is TObj view ? Equals(view) : obj is TComType com && Equals(com)); /// Indicates whether the current object is equal to another object of the same type. /// An object to compare with this object. /// true if the current object is equal to the parameter; otherwise, false. public abstract bool Equals(TComType? other); /// Indicates whether the current object is equal to another object of the same type. /// An object to compare with this object. /// true if the current object is equal to the parameter; otherwise, false. public virtual bool Equals(TObj other) => Equals(other.iObj); /// Returns a hash code for this instance. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. public abstract override int GetHashCode(); /// Called when a property's value has changed. /// Name of the property. protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); }