using System; namespace NvAPIWrapper.GPU { /// /// Contains information about the PCI connection /// public class PCIIdentifiers : IEquatable { // ReSharper disable once TooManyDependencies internal PCIIdentifiers(uint deviceId, uint subSystemId, uint revisionId, int externalDeviceId = 0) { DeviceId = deviceId; SubSystemId = subSystemId; RevisionId = revisionId; if (externalDeviceId > 0) { ExternalDeviceId = (ushort) externalDeviceId; } else { ExternalDeviceId = (ushort) (deviceId >> 16); } VendorId = (ushort) ((DeviceId << 16) >> 16); } /// /// Gets the internal PCI device identifier /// public uint DeviceId { get; } /// /// Gets the external PCI device identifier /// public ushort ExternalDeviceId { get; } /// /// Gets the internal PCI device-specific revision identifier /// public uint RevisionId { get; } /// /// Gets the internal PCI subsystem identifier /// public uint SubSystemId { get; } /// /// Gets the vendor identification calculated from internal device identification /// public ushort VendorId { get; } /// public bool Equals(PCIIdentifiers other) { return DeviceId == other.DeviceId && SubSystemId == other.SubSystemId && RevisionId == other.RevisionId; } /// /// Checks for equality between two objects of same type /// /// The first object /// The second object /// true, if both objects are equal, otherwise false public static bool operator ==(PCIIdentifiers left, PCIIdentifiers right) { return left.Equals(right); } /// /// Checks for inequality between two objects of same type /// /// The first object /// The second object /// true, if both objects are not equal, otherwise false public static bool operator !=(PCIIdentifiers left, PCIIdentifiers right) { return !left.Equals(right); } /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } return obj is PCIIdentifiers identifiers && Equals(identifiers); } /// public override int GetHashCode() { unchecked { var hashCode = (int) DeviceId; hashCode = (hashCode * 397) ^ (int) SubSystemId; hashCode = (hashCode * 397) ^ (int) RevisionId; return hashCode; } } /// public override string ToString() { return $"PCI\\VEN_{VendorId:X}&DEV_{ExternalDeviceId:X}&SUBSYS_{SubSystemId:X}&REV_{RevisionId:X}"; } } }