Skip to content

Commit

Permalink
Refine GetHashCode() in DisplayDeviceW
Browse files Browse the repository at this point in the history
  • Loading branch information
kenelin committed Aug 29, 2020
1 parent 897f0b8 commit 3e4572a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions source/Htc.Vita.Core/Interop/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,17 +1224,26 @@ internal enum WinTrustDataUIContext : uint
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct DisplayDeviceW : IEquatable<DisplayDeviceW>
{
internal /* DWORD */ int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] internal /* WCHAR[32] */ string deviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal /* WCHAR[128] */ string deviceString;
internal /* DWORD */ DisplayDeviceStateFlags stateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal /* WCHAR[128] */ string deviceId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal /* WCHAR[128] */ string deviceKey;
internal /* DWORD */ int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] internal readonly /* WCHAR[32] */ string deviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal readonly /* WCHAR[128] */ string deviceString;
internal readonly /* DWORD */ DisplayDeviceStateFlags stateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal readonly /* WCHAR[128] */ string deviceId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] internal readonly /* WCHAR[128] */ string deviceKey;

public static bool operator ==(DisplayDeviceW left, DisplayDeviceW right)
{
return Equals(left, right);
}

public static bool operator !=(DisplayDeviceW left, DisplayDeviceW right)
{
return !Equals(left, right);
}

public bool Equals(DisplayDeviceW other)
{
return cb == other.cb
&& deviceName == other.deviceName
return deviceName == other.deviceName
&& deviceString == other.deviceString
&& stateFlags == other.stateFlags
&& deviceId == other.deviceId
Expand All @@ -1254,8 +1263,7 @@ public override int GetHashCode()
{
unchecked
{
var hashCode = cb;
hashCode = (hashCode * 397) ^ (deviceName != null ? deviceName.GetHashCode() : 0);
var hashCode = (deviceName != null ? deviceName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (deviceString != null ? deviceString.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) stateFlags;
hashCode = (hashCode * 397) ^ (deviceId != null ? deviceId.GetHashCode() : 0);
Expand Down

0 comments on commit 3e4572a

Please sign in to comment.