using System; using System.Collections.Generic; using System.Text; using Interop.VixCOM; namespace Vestris.VMWareLib { /// /// A wrapper for a VixCOM handle. /// /// Type of VixCOM handle. /// /// Most VixCOM objects returned from VixCOM API functions implement IVixHandle. /// public class VMWareVixHandle : IDisposable { /// /// Raw VixCOM handle of implemented type. /// protected T _handle = default(T); /// /// Pointer to the IVixHandle interface. /// protected IVixHandle _vixhandle { get { return _handle as IVixHandle; } } /// /// Pointer to the IVixHandle2 interface. /// /// /// This type was introduced in VixCOM 1.7.0 and will return null with older versions of VixCOM. /// protected IVixHandle2 _vixhandle2 { get { return _handle as IVixHandle2; } } /// /// A constructor for a null Vix handle. /// public VMWareVixHandle() { } /// /// A constructor for an existing Vix handle. /// /// handle value public VMWareVixHandle(T handle) { _handle = handle; } /// /// Get an array of properties. /// /// properties to fetch /// An array of property values. public object[] GetProperties(object[] properties) { object result = null; VMWareInterop.Check(_vixhandle.GetProperties(properties, ref result)); return (object[])result; } /// /// Return the value of a single property. /// /// property id /// property value type /// The value of a single property of type R. public R GetProperty(int propertyId) { object[] properties = { propertyId }; return (R)GetProperties(properties)[0]; } /// /// Close the handle. /// public void Close() { if (_vixhandle2 != null) { _vixhandle2.Close(); _handle = default(T); } } #region IDisposable Members /// /// Close the handle with VixCOM 1.7.0 or newer. /// public virtual void Dispose() { Close(); } #endregion } }