diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-02-09 12:51:06 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2022-02-10 06:52:37 +0000 |
commit | f17daf02e5573077a3da9d2f71a3d5500413e0b1 (patch) | |
tree | 36bd57065789011f2cd36684c25493d76d4c9101 /QtVsTools.Core | |
parent | 134748d4634c5005fa9e4e97994c921660388b01 (diff) |
Inline variable declaration
Change-Id: I19a55a53173da4e6e5aeea5f40790b1dea6346ec
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Diffstat (limited to 'QtVsTools.Core')
-rw-r--r-- | QtVsTools.Core/CommandLineParser.cs | 15 | ||||
-rw-r--r-- | QtVsTools.Core/Common/EnumExt.cs | 3 | ||||
-rw-r--r-- | QtVsTools.Core/Messages.cs | 3 | ||||
-rw-r--r-- | QtVsTools.Core/MsBuildProject.cs | 21 | ||||
-rw-r--r-- | QtVsTools.Core/QMakeQuery.cs | 6 | ||||
-rw-r--r-- | QtVsTools.Core/QtModules.cs | 3 | ||||
-rw-r--r-- | QtVsTools.Core/QtMsBuild.cs | 34 | ||||
-rw-r--r-- | QtVsTools.Core/VisualStudio/VsServiceProvider.cs | 6 | ||||
-rw-r--r-- | QtVsTools.Core/WaitDialog.cs | 12 |
9 files changed, 37 insertions, 66 deletions
diff --git a/QtVsTools.Core/CommandLineParser.cs b/QtVsTools.Core/CommandLineParser.cs index f66d0ef7..1b969367 100644 --- a/QtVsTools.Core/CommandLineParser.cs +++ b/QtVsTools.Core/CommandLineParser.cs @@ -117,8 +117,7 @@ namespace QtVsTools.Core.CommandLine IEnumerable<string> Aliases(string optionName) { - int optionIndex; - if (!nameHash.TryGetValue(optionName, out optionIndex)) { + if (!nameHash.TryGetValue(optionName, out int optionIndex)) { return new List<string>(); } return commandLineOptionList[optionIndex].Names; @@ -203,8 +202,7 @@ namespace QtVsTools.Core.CommandLine IEnumerator<string> argumentEnumerator, ref bool atEnd) { const char assignChar = '='; - int optionOffset; - if (nameHash.TryGetValue(optionName, out optionOffset)) { + if (nameHash.TryGetValue(optionName, out int optionOffset)) { int assignPos = argument.IndexOf(assignChar); bool withValue = !string.IsNullOrEmpty( commandLineOptionList[optionOffset].ValueName); @@ -355,10 +353,9 @@ namespace QtVsTools.Core.CommandLine if (!RegisterFoundOption(optionName)) { error = true; } else { - int optionOffset; Trace.Assert(nameHash.TryGetValue( optionName, - out optionOffset)); + out int optionOffset)); bool withValue = !string.IsNullOrEmpty( commandLineOptionList[optionOffset].ValueName); if (withValue) { @@ -396,10 +393,9 @@ namespace QtVsTools.Core.CommandLine if (argument.Length > 2) { string possibleShortOptionStyleName = argument.Substring(1, 1); - int shortOptionIdx; if (nameHash.TryGetValue( possibleShortOptionStyleName, - out shortOptionIdx)) { + out int shortOptionIdx)) { var arg = commandLineOptionList[shortOptionIdx]; if ((arg.Flags & Option.Flag.ShortOptionStyle) != 0) { RegisterFoundOption(possibleShortOptionStyleName); @@ -465,8 +461,7 @@ namespace QtVsTools.Core.CommandLine public IEnumerable<string> Values(string optionName) { CheckParsed("Values"); - int optionOffset; - if (nameHash.TryGetValue(optionName, out optionOffset)) { + if (nameHash.TryGetValue(optionName, out int optionOffset)) { var values = optionValuesHash[optionOffset]; return values; } diff --git a/QtVsTools.Core/Common/EnumExt.cs b/QtVsTools.Core/Common/EnumExt.cs index 79d84d01..d7e705d6 100644 --- a/QtVsTools.Core/Common/EnumExt.cs +++ b/QtVsTools.Core/Common/EnumExt.cs @@ -128,8 +128,7 @@ namespace QtVsTools.Common /// </summary> public static TEnum Cast<T, TEnum>(this T valueT, TEnum defaultValue) where TEnum : struct { - TEnum value; - return TryCast(valueT, out value) ? value : defaultValue; + return TryCast(valueT, out TEnum value) ? value : defaultValue; } /// <summary> diff --git a/QtVsTools.Core/Messages.cs b/QtVsTools.Core/Messages.cs index 0f2680a7..aa39acfd 100644 --- a/QtVsTools.Core/Messages.cs +++ b/QtVsTools.Core/Messages.cs @@ -238,8 +238,7 @@ namespace QtVsTools.Core if (!await MessageReady.ToTask(3000)) continue; while (!msgQueue.IsEmpty) { - Msg msg; - if (!msgQueue.TryDequeue(out msg)) { + if (!msgQueue.TryDequeue(out Msg msg)) { await Task.Yield(); continue; } diff --git a/QtVsTools.Core/MsBuildProject.cs b/QtVsTools.Core/MsBuildProject.cs index 2efdad5a..01105838 100644 --- a/QtVsTools.Core/MsBuildProject.cs +++ b/QtVsTools.Core/MsBuildProject.cs @@ -375,10 +375,8 @@ namespace QtVsTools.Core foreach (var pg in uncategorizedPropertyGroups) { foreach (var p in pg.Elements().ToList()) { var condition = p.Attribute("Condition") ?? pg.Attribute("Condition"); - XElement configPropertyGroup = null; - if (condition != null) - propertyGroups.TryGetValue((string)condition, out configPropertyGroup); - if (configPropertyGroup != null) { + if (condition != null && propertyGroups + .TryGetValue((string)condition, out XElement configPropertyGroup)) { p.Remove(); p.SetAttributeValue("Condition", null); configPropertyGroup.Add(p); @@ -524,12 +522,10 @@ namespace QtVsTools.Core foreach (var configQtSettings in qtSettings) { var configCondition = (string)configQtSettings.Attribute("Condition"); - XElement oldConfigQtInstall; - if (oldQtInstall.TryGetValue(configCondition, out oldConfigQtInstall)) + if (oldQtInstall.TryGetValue(configCondition, out XElement oldConfigQtInstall)) configQtSettings.Add(oldConfigQtInstall); - XElement oldConfigQtSettings; - if (oldQtSettings.TryGetValue(configCondition, out oldConfigQtSettings)) { + if (oldQtSettings.TryGetValue(configCondition, out XElement oldConfigQtSettings)) { foreach (var qtSetting in oldConfigQtSettings.Elements()) configQtSettings.Add(qtSetting); } @@ -1050,8 +1046,7 @@ namespace QtVsTools.Core return (string)cbt.Attribute("Include"); } } - string ouputFile; - if (!properties.TryGetValue(QtMoc.Property.InputFile, out ouputFile)) + if (!properties.TryGetValue(QtMoc.Property.InputFile, out string ouputFile)) return (string)cbt.Attribute("Include"); return ouputFile; } @@ -1076,8 +1071,7 @@ namespace QtVsTools.Core Path.IsPathRooted(x) ? x : Path.Combine(projDir, x))); var outputItems = new List<XElement>(); foreach (var outputFile in outputFiles) { - List<XElement> mocOutput = null; - if (projItemsByPath.TryGetValue(outputFile, out mocOutput)) { + if (projItemsByPath.TryGetValue(outputFile, out List<XElement> mocOutput)) { outputItems.AddRange(mocOutput); hasGeneratedFiles |= hasGeneratedFiles ? true : mocOutput .Where(x => !x.Elements(ns + "ExcludedFromBuild") @@ -1514,8 +1508,7 @@ namespace QtVsTools.Core public string ExpandString(string stringToExpand) { - string expandedString; - if (TryExpansionCache(stringToExpand, out expandedString)) + if (TryExpansionCache(stringToExpand, out string expandedString)) return expandedString; if (evaluateTarget == null) { diff --git a/QtVsTools.Core/QMakeQuery.cs b/QtVsTools.Core/QMakeQuery.cs index 9e79bbea..5d942839 100644 --- a/QtVsTools.Core/QMakeQuery.cs +++ b/QtVsTools.Core/QMakeQuery.cs @@ -81,11 +81,9 @@ namespace QtVsTools.Core { ThreadHelper.ThrowIfNotOnUIThread(); - string value = string.Empty; - if (Properties.TryGetValue(name, out value)) + if (Properties.TryGetValue(name, out string value)) return value; - else - return null; + return null; } } diff --git a/QtVsTools.Core/QtModules.cs b/QtVsTools.Core/QtModules.cs index 76b5c08d..4b4bd8c4 100644 --- a/QtVsTools.Core/QtModules.cs +++ b/QtVsTools.Core/QtModules.cs @@ -44,8 +44,7 @@ namespace QtVsTools.Core public QtModule Module(int id) { - QtModule module; - modules.TryGetValue(id, out module); + modules.TryGetValue(id, out QtModule module); return module; } diff --git a/QtVsTools.Core/QtMsBuild.cs b/QtVsTools.Core/QtMsBuild.cs index 25d2d898..705070f6 100644 --- a/QtVsTools.Core/QtMsBuild.cs +++ b/QtVsTools.Core/QtMsBuild.cs @@ -205,8 +205,7 @@ namespace QtVsTools.Core.QtMsBuild void AddChange(ItemPropertyChange newChange) { - ItemPropertyChange oldChange; - if (itemPropertyChanges.TryGetValue(newChange.Key, out oldChange)) { + if (itemPropertyChanges.TryGetValue(newChange.Key, out ItemPropertyChange oldChange)) { if (oldChange.GroupKey == newChange.GroupKey) { oldChange.CopyFrom(newChange); return; @@ -883,14 +882,13 @@ namespace QtVsTools.Core.QtMsBuild { properties = new Dictionary<Property, string>(); - string qtDir, inputPath, outputPath; if (!ParseCommandLine( commandLine, macros, ToolExecName, - out qtDir, - out inputPath, - out outputPath)) { + out string qtDir, + out string inputPath, + out string outputPath)) { return false; } @@ -1132,14 +1130,13 @@ namespace QtVsTools.Core.QtMsBuild { properties = new Dictionary<Property, string>(); - string qtDir, inputPath, outputPath; if (!ParseCommandLine( commandLine, macros, ToolExecName, - out qtDir, - out inputPath, - out outputPath)) { + out string qtDir, + out string inputPath, + out string outputPath)) { return false; } @@ -1159,8 +1156,7 @@ namespace QtVsTools.Core.QtMsBuild properties[Property.Root] = parser.Value(options[Property.Root]); if (parser.IsSet(options[Property.Compression])) { - int level; - if (!int.TryParse(parser.Value(options[Property.Compression]), out level)) + if (!int.TryParse(parser.Value(options[Property.Compression]), out int level)) return false; if (level < 1 || 9 < level) return false; @@ -1332,14 +1328,13 @@ namespace QtVsTools.Core.QtMsBuild { properties = new Dictionary<Property, string>(); - string qtDir, inputPath, outputPath; if (!ParseCommandLine( commandLine, macros, ToolExecName, - out qtDir, - out inputPath, - out outputPath)) { + out string qtDir, + out string inputPath, + out string outputPath)) { return false; } @@ -1475,14 +1470,13 @@ namespace QtVsTools.Core.QtMsBuild { properties = new Dictionary<Property, string>(); - string qtDir, inputPath, outputPath; if (!ParseCommandLine( commandLine, macros, ToolExecName, - out qtDir, - out inputPath, - out outputPath)) { + out string qtDir, + out string inputPath, + out string outputPath)) { return false; } diff --git a/QtVsTools.Core/VisualStudio/VsServiceProvider.cs b/QtVsTools.Core/VisualStudio/VsServiceProvider.cs index dba16e89..349ed847 100644 --- a/QtVsTools.Core/VisualStudio/VsServiceProvider.cs +++ b/QtVsTools.Core/VisualStudio/VsServiceProvider.cs @@ -60,8 +60,7 @@ namespace QtVsTools.VisualStudio if (Instance == null) return null; - object serviceObj; - if (services.TryGetValue(new ServiceType(typeof(T), typeof(I)), out serviceObj)) + if (services.TryGetValue(new ServiceType(typeof(T), typeof(I)), out object serviceObj)) return serviceObj as I; var serviceInterface = Instance.GetService<T, I>(); @@ -82,8 +81,7 @@ namespace QtVsTools.VisualStudio if (Instance == null) return null; - object serviceObj; - if (services.TryGetValue(new ServiceType(typeof(T), typeof(I)), out serviceObj)) + if (services.TryGetValue(new ServiceType(typeof(T), typeof(I)), out object serviceObj)) return serviceObj as I; var serviceInterface = await Instance.GetServiceAsync<T, I>(); diff --git a/QtVsTools.Core/WaitDialog.cs b/QtVsTools.Core/WaitDialog.cs index 819bdc76..cedc078c 100644 --- a/QtVsTools.Core/WaitDialog.cs +++ b/QtVsTools.Core/WaitDialog.cs @@ -56,8 +56,7 @@ namespace QtVsTools.Core ThreadHelper.ThrowIfNotOnUIThread(); - bool canceled = false; - int res = VsWaitDialog.HasCanceled(out canceled); + int res = VsWaitDialog.HasCanceled(out bool canceled); if (res != VSConstants.S_OK) return false; @@ -82,8 +81,7 @@ namespace QtVsTools.Core ThreadHelper.ThrowIfNotOnUIThread(); - IVsThreadedWaitDialog2 vsWaitDialog = null; - factory.CreateInstance(out vsWaitDialog); + factory.CreateInstance(out IVsThreadedWaitDialog2 vsWaitDialog); if (vsWaitDialog == null) return null; @@ -159,9 +157,8 @@ namespace QtVsTools.Core ThreadHelper.ThrowIfNotOnUIThread(); - bool canceled = false; int res = VsWaitDialog.UpdateProgress(message, progressText, - statusBarText, currentStep, totalSteps, disableCancel, out canceled); + statusBarText, currentStep, totalSteps, disableCancel, out bool canceled); if (res != VSConstants.S_OK) return; @@ -178,8 +175,7 @@ namespace QtVsTools.Core ThreadHelper.ThrowIfNotOnUIThread(); Running = false; - int canceled = 0; - VsWaitDialog.EndWaitDialog(out canceled); + VsWaitDialog.EndWaitDialog(out int canceled); Canceled = (canceled != 0); } |