From fb614817392f7c2a81c981166a193bd581bfbd68 Mon Sep 17 00:00:00 2001 From: Corniel Nobel Date: Tue, 5 Mar 2024 09:54:57 +0100 Subject: [PATCH] Update PR. --- src/Buildalyzer/AnalyzerResult.cs | 14 ++++---------- src/Buildalyzer/Compiler/CompilerProperties.cs | 2 +- src/Buildalyzer/Logging/EventProcessor.cs | 18 ++++++++---------- src/Buildalyzer/Properties/GlobalUsings.cs | 1 + 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/Buildalyzer/AnalyzerResult.cs b/src/Buildalyzer/AnalyzerResult.cs index b44520bb..23fff213 100644 --- a/src/Buildalyzer/AnalyzerResult.cs +++ b/src/Buildalyzer/AnalyzerResult.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using Buildalyzer.Construction; using Buildalyzer.Logging; -using Microsoft.Build.Framework; namespace Buildalyzer; @@ -162,15 +156,15 @@ public string GetProperty(string name) => internal void ProcessProject(PropertiesAndItems propertiesAndItems) { // Add properties - foreach (DictionaryEntry entry in propertiesAndItems.Properties.ToDictionaryEntries()) + foreach (var entry in propertiesAndItems.Properties) { - _properties[entry.Key.ToString()] = entry.Value.ToString(); + _properties[entry.Key] = entry.StringValue; } // Add items - foreach (IGrouping itemGroup in propertiesAndItems.Items.ToDictionaryEntries().GroupBy(x => x.Key.ToString())) + foreach (var items in propertiesAndItems.Items) { - _items[itemGroup.Key] = itemGroup.Select(x => new ProjectItem((ITaskItem)x.Value)).ToArray(); + _items[items.Key] = items.Values.Select(task => new ProjectItem(task)).ToArray(); } } diff --git a/src/Buildalyzer/Compiler/CompilerProperties.cs b/src/Buildalyzer/Compiler/CompilerProperties.cs index c4a9fdf4..9abafdf8 100644 --- a/src/Buildalyzer/Compiler/CompilerProperties.cs +++ b/src/Buildalyzer/Compiler/CompilerProperties.cs @@ -11,7 +11,7 @@ public sealed class CompilerProperties : IReadOnlyCollection #pragma warning restore CA1710 // Identifiers should have correct suffix { [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly Dictionary _values = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary _values = new(StringComparer.OrdinalIgnoreCase); private CompilerProperties() { diff --git a/src/Buildalyzer/Logging/EventProcessor.cs b/src/Buildalyzer/Logging/EventProcessor.cs index f83da768..c78e4ecd 100644 --- a/src/Buildalyzer/Logging/EventProcessor.cs +++ b/src/Buildalyzer/Logging/EventProcessor.cs @@ -70,8 +70,8 @@ private void StatusEventRaised(object sender, BuildStatusEventArgs e) { _evalulationResults[slEv.BuildEventContext.EvaluationId] = new PropertiesAndItems { - Properties = slEv.Properties, - Items = slEv.Items + Properties = CompilerProperties.FromDictionaryEntries(slEv.Properties), + Items = CompilerItemsCollection.FromDictionaryEntries(slEv.Items), }; } } @@ -94,17 +94,15 @@ private void ProjectStarted(object sender, ProjectStartedEventArgs e) : null) : new PropertiesAndItems { - Properties = e.Properties, - Items = e.Items + Properties = CompilerProperties.FromDictionaryEntries(e.Properties), + Items = CompilerItemsCollection.FromDictionaryEntries(e.Items), }; // Get the TFM for this project - string tfm = propertiesAndItems - ?.Properties - ?.ToDictionaryEntries() - .FirstOrDefault(x => string.Equals(x.Key.ToString(), "TargetFrameworkMoniker", StringComparison.OrdinalIgnoreCase)) - .Value - ?.ToString() ?? string.Empty; // use an empty string if no target framework was found, for example in case of C++ projects with VS >= 2022 + // use an empty string if no target framework was found, for example in case of C++ projects with VS >= 2022 + var tfm = propertiesAndItems?.Properties.TryGet("TargetFrameworkMoniker")?.StringValue + ?? string.Empty; + if (propertiesAndItems != null && propertiesAndItems.Properties != null && propertiesAndItems.Items != null) { if (!_results.TryGetValue(tfm, out AnalyzerResult result)) diff --git a/src/Buildalyzer/Properties/GlobalUsings.cs b/src/Buildalyzer/Properties/GlobalUsings.cs index ef4852e5..150d0336 100644 --- a/src/Buildalyzer/Properties/GlobalUsings.cs +++ b/src/Buildalyzer/Properties/GlobalUsings.cs @@ -1,4 +1,5 @@ global using System; +global using System.Collections; global using System.Collections.Generic; global using System.Collections.Immutable; global using System.Diagnostics;