Skip to content

Commit 1217068

Browse files
Moved CommandLookupKey to new file
1 parent ae3c26c commit 1217068

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

Engine/CommandLookupKey.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Management.Automation;
6+
7+
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
8+
{
9+
internal struct CommandLookupKey : IEquatable<CommandLookupKey>
10+
{
11+
private readonly string Name;
12+
13+
private readonly CommandTypes CommandTypes;
14+
15+
internal CommandLookupKey(string name, CommandTypes? commandTypes)
16+
{
17+
Name = name;
18+
CommandTypes = commandTypes ?? CommandTypes.All;
19+
}
20+
21+
public bool Equals(CommandLookupKey other)
22+
{
23+
return CommandTypes == other.CommandTypes
24+
&& Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase);
25+
}
26+
27+
public override int GetHashCode()
28+
{
29+
// Algorithm from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
30+
unchecked
31+
{
32+
int hash = 17;
33+
hash = hash * 31 + Name.ToUpperInvariant().GetHashCode();
34+
hash = hash * 31 + CommandTypes.GetHashCode();
35+
return hash;
36+
}
37+
}
38+
}
39+
}

Engine/Helper.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,37 +1912,6 @@ public Version GetPSVersion()
19121912
}
19131913

19141914
#endregion Methods
1915-
1916-
private struct CommandLookupKey : IEquatable<CommandLookupKey>
1917-
{
1918-
private readonly string Name;
1919-
1920-
private readonly CommandTypes CommandTypes;
1921-
1922-
internal CommandLookupKey(string name, CommandTypes? commandTypes)
1923-
{
1924-
Name = name;
1925-
CommandTypes = commandTypes ?? CommandTypes.All;
1926-
}
1927-
1928-
public bool Equals(CommandLookupKey other)
1929-
{
1930-
return CommandTypes == other.CommandTypes
1931-
&& Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase);
1932-
}
1933-
1934-
public override int GetHashCode()
1935-
{
1936-
// Algorithm from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
1937-
unchecked
1938-
{
1939-
int hash = 17;
1940-
hash = hash * 31 + Name.ToUpperInvariant().GetHashCode();
1941-
hash = hash * 31 + CommandTypes.GetHashCode();
1942-
return hash;
1943-
}
1944-
}
1945-
}
19461915
}
19471916

19481917

0 commit comments

Comments
 (0)