Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
PropertyKey.cs121 linesDownload Raw Back to WindowsTaskbarJumpList
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Runtime.InteropServices;6 7namespace Microsoft.PowerShell8{9    /// <summary>10    /// Defines a unique key for a Shell Property.11    /// </summary>12    [StructLayout(LayoutKind.Sequential, Pack = 4)]13    internal readonly struct PropertyKey : IEquatable<PropertyKey>14    {15        #region Public Properties16        /// <summary>17        /// A unique GUID for the property.18        /// </summary>19        public Guid FormatId { get; }20 21        /// <summary>22        /// Property identifier (PID)23        /// </summary>24        public int PropertyId { get; }25 26        #endregion27 28        #region Public Construction29 30        /// <summary>31        /// PropertyKey Constructor.32        /// </summary>33        /// <param name="formatId">A unique GUID for the property.</param>34        /// <param name="propertyId">Property identifier (PID).</param>35        internal PropertyKey(Guid formatId, int propertyId)36        {37            this.FormatId = formatId;38            this.PropertyId = propertyId;39        }40 41        #endregion42 43        #region IEquatable<PropertyKey> Members44 45        /// <summary>46        /// Returns whether this object is equal to another. This is vital for performance of value types.47        /// </summary>48        /// <param name="other">The object to compare against.</param>49        /// <returns>Equality result.</returns>50        public bool Equals(PropertyKey other)51        {52            return other.Equals((object)this);53        }54 55        #endregion56 57        #region equality and hashing58 59        /// <summary>60        /// Returns the hash code of the object. This is vital for performance of value types.61        /// </summary>62        /// <returns></returns>63        public override int GetHashCode()64        {65            return FormatId.GetHashCode() ^ PropertyId;66        }67 68        /// <summary>69        /// Returns whether this object is equal to another. This is vital for performance of value types.70        /// </summary>71        /// <param name="obj">The object to compare against.</param>72        /// <returns>Equality result.</returns>73        public override bool Equals(object obj)74        {75            if (obj == null)76                return false;77 78            if (obj is not PropertyKey)79                return false;80 81            PropertyKey other = (PropertyKey)obj;82            return other.FormatId.Equals(FormatId) && (other.PropertyId == PropertyId);83        }84 85        /// <summary>86        /// Implements the == (equality) operator.87        /// </summary>88        /// <param name="propKey1">First property key to compare.</param>89        /// <param name="propKey2">Second property key to compare.</param>90        /// <returns>True if object a equals object b. false otherwise.</returns>91        public static bool operator ==(PropertyKey propKey1, PropertyKey propKey2)92        {93            return propKey1.Equals(propKey2);94        }95 96        /// <summary>97        /// Implements the != (inequality) operator.98        /// </summary>99        /// <param name="propKey1">First property key to compare.</param>100        /// <param name="propKey2">Second property key to compare.</param>101        /// <returns>True if object a does not equal object b. false otherwise.</returns>102        public static bool operator !=(PropertyKey propKey1, PropertyKey propKey2)103        {104            return !propKey1.Equals(propKey2);105        }106 107        /// <summary>108        /// Override ToString() to provide a user friendly string representation.109        /// </summary>110        /// <returns>String representing the property key.</returns>111        public override string ToString()112        {113            return string.Format(System.Globalization.CultureInfo.InvariantCulture,114                "PropertyKeyFormatString",115                FormatId.ToString("B"), PropertyId);116        }117 118        #endregion119    }120}121