Skip to content

Commit 37a5462

Browse files
authored
Merge pull request github#13688 from michaelnebel/csharp/aspnetcore
C#: Turn RuntimeVersion into a record type.
2 parents 5862cd2 + 6bb9e6d commit 37a5462

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Runtime.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal partial class Runtime
2222

2323
public Runtime(IDotNet dotNet) => this.dotNet = dotNet;
2424

25-
internal sealed class RuntimeVersion : IComparable<RuntimeVersion>
25+
internal record RuntimeVersion : IComparable<RuntimeVersion>
2626
{
2727
private readonly string dir;
2828
private readonly Version version;
@@ -71,11 +71,6 @@ public int CompareTo(RuntimeVersion? other)
7171
return c;
7272
}
7373

74-
public override bool Equals(object? obj) =>
75-
obj is not null && obj is RuntimeVersion other && other.FullPath == FullPath;
76-
77-
public override int GetHashCode() => FullPath.GetHashCode();
78-
7974
public override string ToString() => FullPath;
8075
}
8176

@@ -97,7 +92,7 @@ private static Dictionary<string, RuntimeVersion> ParseRuntimes(IList<string> li
9792
var match = RuntimeRegex().Match(r);
9893
if (match.Success)
9994
{
100-
runtimes.AddOrUpdate(match.Groups[1].Value, new RuntimeVersion(match.Groups[6].Value, match.Groups[2].Value, match.Groups[4].Value, match.Groups[5].Value));
95+
runtimes.AddOrUpdateToLatest(match.Groups[1].Value, new RuntimeVersion(match.Groups[6].Value, match.Groups[2].Value, match.Groups[4].Value, match.Groups[5].Value));
10196
}
10297
});
10398

csharp/extractor/Semmle.Util/DictionaryExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public static void AddAnother<T1, T2>(this Dictionary<T1, List<T2>> dict, T1 key
2222

2323
/// <summary>
2424
/// Adds a new value or replaces the existing value (if the new value is greater than the existing)
25-
/// in dictionary for the given key.
25+
/// in this dictionary for the given key.
2626
/// </summary>
27-
public static void AddOrUpdate<T1, T2>(this Dictionary<T1, T2> dict, T1 key, T2 value) where T1 : notnull where T2 : IComparable<T2>
27+
public static void AddOrUpdateToLatest<T1, T2>(this Dictionary<T1, T2> dict, T1 key, T2 value) where T1 : notnull where T2 : IComparable<T2>
2828
{
2929
if (!dict.TryGetValue(key, out var existing) || existing.CompareTo(value) < 0)
3030
{

0 commit comments

Comments
 (0)