diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-11-08 09:55:23 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-11-21 12:54:46 +0000 |
commit | d525eda70e510d1f60d96cb40dfe86acc3c7c877 (patch) | |
tree | 5788f389397740e492b1fac940abfaeba776af4c | |
parent | 43c03f7b24b7eb76c7702a1154808b74ae168b05 (diff) |
Simplify some LINQ code, adjust some warnings
* Remove redundant parameter type specification
* Simplify some LINQ calls and use method groups
* Fix multiple enumeration runs and store as List
Change-Id: Id752efa0b3994928f4d0a17551d24a7d25834957
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r-- | QtVsTools.Core/HelperFunctions.cs | 3 | ||||
-rw-r--r-- | QtVsTools.Core/QMake.cs | 7 | ||||
-rw-r--r-- | QtVsTools.Core/QMakeQuery.cs | 2 | ||||
-rw-r--r-- | QtVsTools.Core/VersionInformation.cs | 8 | ||||
-rw-r--r-- | QtVsTools.Package/Options/QtVersionsTable.cs | 6 | ||||
-rw-r--r-- | QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs | 10 |
6 files changed, 17 insertions, 19 deletions
diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs index 2dca52ae..5025feb2 100644 --- a/QtVsTools.Core/HelperFunctions.cs +++ b/QtVsTools.Core/HelperFunctions.cs @@ -1513,8 +1513,7 @@ namespace QtVsTools.Core // Warn if cl.exe is not in PATH string clPath = envVars["PATH"] .Select(path => Path.Combine(path, "cl.exe")) - .Where(pathToCl => File.Exists(pathToCl)) - .FirstOrDefault(); + .FirstOrDefault(File.Exists); Messages.Print($"cl: {clPath ?? "NOT FOUND"}"); return true; diff --git a/QtVsTools.Core/QMake.cs b/QtVsTools.Core/QMake.cs index 0bf0caef..298fc95c 100644 --- a/QtVsTools.Core/QMake.cs +++ b/QtVsTools.Core/QMake.cs @@ -211,10 +211,9 @@ namespace QtVsTools.Core Path.Combine(path, "bin", "qmake.exe"), Path.Combine(path, "bin", "qmake.bat"), }; - return possibleQMakePaths.Where(p => File.Exists(p) - && (Path.GetFileName(p).Equals("qmake.exe", StringComparison.OrdinalIgnoreCase) - || Path.GetFileName(p).Equals("qmake.bat", StringComparison.OrdinalIgnoreCase))) - .Any(); + return possibleQMakePaths.Where(File.Exists).Select(Path.GetFileName) + .Any(file => file.Equals("qmake.exe", StringComparison.OrdinalIgnoreCase) + || file.Equals("qmake.bat", StringComparison.OrdinalIgnoreCase)); } } diff --git a/QtVsTools.Core/QMakeQuery.cs b/QtVsTools.Core/QMakeQuery.cs index 2992f39d..ce112a47 100644 --- a/QtVsTools.Core/QMakeQuery.cs +++ b/QtVsTools.Core/QMakeQuery.cs @@ -63,7 +63,7 @@ namespace QtVsTools.Core .Parse(stdOutput.ToString()) .GetValues<KeyValuePair<string, string>>("PROP") .GroupBy(x => x.Key) - .Select(x => new { x.Key, Value = x.Last().Value }) + .Select(x => new { x.Key, x.Last().Value }) .ToDictionary(property => property.Key, property => property.Value); } else { return new Dictionary<string, string>(); diff --git a/QtVsTools.Core/VersionInformation.cs b/QtVsTools.Core/VersionInformation.cs index a6a83cf2..ba763685 100644 --- a/QtVsTools.Core/VersionInformation.cs +++ b/QtVsTools.Core/VersionInformation.cs @@ -143,7 +143,7 @@ namespace QtVsTools.Core tempProData.AppendLine("SOURCES = main.cpp"); var modules = QtModules.Instance.GetAvailableModules(qtMajor) - .Where((QtModule mi) => mi.Selectable); + .Where(mi => mi.Selectable).ToList(); foreach (QtModule mi in modules) { tempProData.AppendLine(string.Format( @@ -167,11 +167,11 @@ namespace QtVsTools.Core Directory.Delete(tempDir, recursive: true); var availableModules = msbuildProj.GetItems("ClInclude") - .Select((string s) => Path.GetFileNameWithoutExtension(s)); + .Select(Path.GetFileNameWithoutExtension); _IsModuleAvailable = modules.ToDictionary( - (QtModule mi) => mi.proVarQT, - (QtModule mi) => availableModules.Contains(mi.proVarQT)); + mi => mi.proVarQT, + mi => availableModules.Contains(mi.proVarQT)); VC_MinimumVisualStudioVersion = msbuildProj.GetProperty("MinimumVisualStudioVersion"); diff --git a/QtVsTools.Package/Options/QtVersionsTable.cs b/QtVsTools.Package/Options/QtVersionsTable.cs index 276e0252..e2e8561c 100644 --- a/QtVsTools.Package/Options/QtVersionsTable.cs +++ b/QtVsTools.Package/Options/QtVersionsTable.cs @@ -213,8 +213,8 @@ namespace QtVsTools.Options version.FieldVersionName.ValidationError = null; if (string.IsNullOrEmpty(version.VersionName)) { version.FieldVersionName.ValidationError = "Name cannot be empty"; - } else if (Versions.Where(otherVersion => otherVersion != version - && otherVersion.VersionName == version.VersionName).Any()) { + } else if (Versions.Any(otherVersion => otherVersion != version + && otherVersion.VersionName == version.VersionName)) { version.FieldVersionName.ValidationError = "Duplicate version names"; } mustRefresh |= version.FieldVersionName.UpdateUi; @@ -449,7 +449,7 @@ namespace QtVsTools.Options { var version = new Row() { - IsDefault = !Versions.Any(x => x.State != State.Removed), + IsDefault = Versions.All(x => x.State == State.Removed), Host = BuildHost.Windows, Path = "", Compiler = "msvc", diff --git a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs index f3984f0c..2bbebbf1 100644 --- a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs +++ b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs @@ -166,14 +166,14 @@ namespace QtVsTools.Wizards.ProjectWizard } var qtModules = QtModules.Instance.GetAvailableModules(defaultQtVersionInfo.qtMajor) - .Where((QtModule mi) => mi.Selectable) - .Select((QtModule mi) => new Module() + .Where(mi => mi.Selectable) + .Select(mi => new Module() { Name = mi.Name, Id = mi.proVarQT, IsSelected = Data.DefaultModules.Contains(mi.LibraryPrefix), IsReadOnly = Data.DefaultModules.Contains(mi.LibraryPrefix), - }); + }).ToList(); defaultConfigs = new CloneableList<Config> { new Config { @@ -192,7 +192,7 @@ namespace QtVsTools.Wizards.ProjectWizard : defaultQtVersionInfo.platform() == Platform.arm64 ? ProjectPlatforms.ARM64.Cast<string>() : string.Empty, - Modules = qtModules.ToDictionary((Module m) => m.Name), + Modules = qtModules.ToDictionary(m => m.Name) }, new Config { Name = "Release", @@ -210,7 +210,7 @@ namespace QtVsTools.Wizards.ProjectWizard : defaultQtVersionInfo.platform() == Platform.arm64 ? ProjectPlatforms.ARM64.Cast<string>() : string.Empty, - Modules = qtModules.ToDictionary((Module m) => m.Name), + Modules = qtModules.ToDictionary(m => m.Name) } }; currentConfigs = defaultConfigs.Clone(); |