diff --git a/src/GitVersion.Core/Core/MergeCommitFinder.cs b/src/GitVersion.Core/Core/MergeCommitFinder.cs index a3c71df94b..11e682dc81 100644 --- a/src/GitVersion.Core/Core/MergeCommitFinder.cs +++ b/src/GitVersion.Core/Core/MergeCommitFinder.cs @@ -24,10 +24,10 @@ public IEnumerable FindMergeCommitsFor(IBranch branch) { branch = branch.NotNull(); - if (this.mergeBaseCommitsCache.ContainsKey(branch)) + if (this.mergeBaseCommitsCache.TryGetValue(branch, out var mergeCommitsFor)) { - this.log.Debug($"Cache hit for getting merge commits for branch {branch?.Name.Canonical}."); - return this.mergeBaseCommitsCache[branch]; + this.log.Debug($"Cache hit for getting merge commits for branch {branch.Name.Canonical}."); + return mergeCommitsFor; } var branchMergeBases = FindMergeBases(branch) diff --git a/src/GitVersion.Core/Extensions/DictionaryExtensions.cs b/src/GitVersion.Core/Extensions/DictionaryExtensions.cs index ade4ffb7c6..7a1ab3723c 100644 --- a/src/GitVersion.Core/Extensions/DictionaryExtensions.cs +++ b/src/GitVersion.Core/Extensions/DictionaryExtensions.cs @@ -6,7 +6,8 @@ public static TValue GetOrAdd(this IDictionary dict, { if (dict is null) throw new ArgumentNullException(nameof(dict)); if (getValue is null) throw new ArgumentNullException(nameof(getValue)); - if (!dict.TryGetValue(key, out TValue value)) + + if (!dict.TryGetValue(key, out var value)) { value = getValue(); dict.Add(key, value); diff --git a/src/GitVersion.Core/Extensions/ObjectExtensions.cs b/src/GitVersion.Core/Extensions/ObjectExtensions.cs index 85857a6ef0..ba9db81686 100644 --- a/src/GitVersion.Core/Extensions/ObjectExtensions.cs +++ b/src/GitVersion.Core/Extensions/ObjectExtensions.cs @@ -16,11 +16,11 @@ public static void Deconstruct( value = kvp.Value; } - public static IEnumerable> GetProperties(this object obj) + public static Dictionary GetProperties(this object obj) { var type = typeof(string); return obj.GetType().GetProperties() .Where(p => p.PropertyType == type && !p.GetIndexParameters().Any() && !p.GetCustomAttributes(typeof(ReflectionIgnoreAttribute), false).Any()) - .Select(p => new KeyValuePair(p.Name, (string)p.GetValue(obj, null))); + .ToDictionary(p => p.Name, p => Convert.ToString(p.GetValue(obj, null))!); } }