diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-21 13:45:08 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2023-02-24 12:37:24 +0000 |
commit | e00a4c602a0cf76b58763b5f84e0457fc7cb2279 (patch) | |
tree | 072c9bb2c74a664dbae1e33e031e5a4f020553d2 | |
parent | a1982adef4f580ae226c3a9e3928ae5d9f867f67 (diff) |
Use string interpolation expression
Change-Id: If5fdcae4b5ea48c2a8ce17d89ca3982232a095f3
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
27 files changed, 105 insertions, 141 deletions
diff --git a/QtVsTest/Macro.cs b/QtVsTest/Macro.cs index a8223923..77966339 100644 --- a/QtVsTest/Macro.cs +++ b/QtVsTest/Macro.cs @@ -509,8 +509,7 @@ namespace QtVsTest.Macros Condition.FalseCondition).ToArray())); } if (uiIterator == null) - throw new Exception( - string.Format("Could not find UI element \"{0}\"", item)); + throw new Exception($"Could not find UI element \"{item}\""); } return uiIterator; } @@ -570,13 +569,13 @@ namespace QtVsTest.Macros string context; if (uiVsRoot) - context = string.Format("UiFind(UiVsRoot, new object[] {{ {0} }})", s.Code); + context = $"UiFind(UiVsRoot, new object[] {{ {s.Code} }})"; else if (uiDesktop) - context = string.Format("UiFind(UiRoot, new object[] {{ {0} }})", s.Code); + context = $"UiFind(UiRoot, new object[] {{ {s.Code} }})"; else if (uiHwnd) - context = string.Format("AutomationElement.FromHandle((IntPtr)({0}))", s.Code); + context = $"AutomationElement.FromHandle((IntPtr)({s.Code}))"; else - context = string.Format("UiFind(UiContext, new object[] {{ {0} }})", s.Code); + context = $"UiFind(UiContext, new object[] {{ {s.Code} }})"; int timeout = 3000; if (s.Args.Count > 1 && !uiVsRoot && !uiDesktop && !uiHwnd) @@ -634,12 +633,12 @@ namespace QtVsTest.Macros string uiElement; if (!string.IsNullOrEmpty(s.Code)) - uiElement = string.Format("UiFind(UiContext, new object[] {{ {0} }})", s.Code); + uiElement = $"UiFind(UiContext, new object[] {{ {s.Code} }})"; else uiElement = "UiContext"; - string patternTypeId = string.Format("{0}PatternIdentifiers.Pattern", typeName); - string patternType = string.Format("{0}Pattern", typeName); + string patternTypeId = $"{typeName}PatternIdentifiers.Pattern"; + string patternType = $"{typeName}Pattern"; if (!string.IsNullOrEmpty(varName)) { @@ -672,7 +671,7 @@ namespace QtVsTest.Macros const string SERVICETYPE_PREFIX = "_ServiceType_"; const string INIT_PREFIX = "_Init_"; - string MethodName => string.Format("_Run_{0}_Async", Name); + string MethodName => $"_Run_{Name}_Async"; bool GenerateClass() { @@ -717,7 +716,7 @@ namespace QtVsTest.Macros globalVar.Name, !string.IsNullOrEmpty(globalVar.InitialValueExpr) ? globalVar.InitialValueExpr - : string.Format("default({0})", globalVar.Type)); + : $"default({globalVar.Type})"); } csharp.Append( @@ -799,7 +798,7 @@ namespace QtVsTest.Macros } MacroAssembly = AppDomain.CurrentDomain.Load(File.ReadAllBytes(macroDllPath)); - MacroClass = MacroAssembly.GetType(string.Format("QtVsTest.Macros.{0}", Name)); + MacroClass = MacroAssembly.GetType($"QtVsTest.Macros.{Name}"); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; if (File.Exists(macroDllPath)) @@ -935,9 +934,8 @@ namespace QtVsTest.Macros if (Globals.TryGetValue(varName, out object value)) { Type valueType = value.GetType(); if (!varType.IsAssignableFrom(valueType)) { - throw new InvalidCastException(string.Format( - "Global variable '{0}': cannot assign '{1}' from '{2}'", - varName, varType.Name, valueType.Name)); + throw new InvalidCastException($"Global variable '{varName}': " + + $"cannot assign '{varType.Name}' from '{valueType.Name}'"); } globalVar.FieldInfo.SetValue(null, value); } else { @@ -1038,8 +1036,7 @@ namespace QtVsTest.Macros bool ErrorException(Exception e) { - Result = MACRO_ERROR_MSG(string.Format("{0}\r\n\"{1}\"\r\n{2}", - e.GetType().Name, e.Message, e.StackTrace)); + Result = MACRO_ERROR_MSG($"{e.GetType().Name}\r\n\"{e.Message}\"\r\n{e.StackTrace}"); return (Ok = false); } diff --git a/QtVsTest/MacroServer.cs b/QtVsTest/MacroServer.cs index ea7844aa..09b2feaa 100644 --- a/QtVsTest/MacroServer.cs +++ b/QtVsTest/MacroServer.cs @@ -50,7 +50,7 @@ namespace QtVsTest.Macros var mainWindowHWnd = new IntPtr((long)dte.MainWindow.HWnd); await TaskScheduler.Default; - var pipeName = string.Format("QtVSTest_{0}", Process.GetCurrentProcess().Id); + var pipeName = $"QtVSTest_{Process.GetCurrentProcess().Id}"; while (!Loop.Token.IsCancellationRequested) { using (var pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut)) { diff --git a/QtVsTools.Package/Editors/Editor.cs b/QtVsTools.Package/Editors/Editor.cs index cdbf0f98..2a0d1809 100644 --- a/QtVsTools.Package/Editors/Editor.cs +++ b/QtVsTools.Package/Editors/Editor.cs @@ -67,8 +67,7 @@ namespace QtVsTools.Editors if (activeConfig == null) return null; - var activeConfigId = string.Format("{0}|{1}", - activeConfig.ConfigurationName, activeConfig.PlatformName); + var activeConfigId = $"{activeConfig.ConfigurationName}|{activeConfig.PlatformName}"; if (vcConfigs.Item(activeConfigId) is VCConfiguration vcConfig) { var qtToolsPath = vcConfig.GetEvaluatedPropertyValue("QtToolsPath"); return string.IsNullOrEmpty(qtToolsPath) ? null : qtToolsPath; diff --git a/QtVsTools.Package/Options/QtOptionsPage.cs b/QtVsTools.Package/Options/QtOptionsPage.cs index cb44df9d..845c80e2 100644 --- a/QtVsTools.Package/Options/QtOptionsPage.cs +++ b/QtVsTools.Package/Options/QtOptionsPage.cs @@ -263,7 +263,7 @@ namespace QtVsTools.Options .Select(x => new { Scope = x.FirstOrDefault(), Shortcut = x.LastOrDefault() }) .FirstOrDefault(); if (binding != null) - QtHelpKeyBinding = string.Format("[{0}] {1}", binding.Scope, binding.Shortcut); + QtHelpKeyBinding = $"[{binding.Scope}] {binding.Shortcut}"; else QtHelpKeyBinding = ""; } diff --git a/QtVsTools.Package/Options/QtVersionsTable.cs b/QtVsTools.Package/Options/QtVersionsTable.cs index 7c253e4d..a2ebd4f6 100644 --- a/QtVsTools.Package/Options/QtVersionsTable.cs +++ b/QtVsTools.Package/Options/QtVersionsTable.cs @@ -501,10 +501,8 @@ namespace QtVsTools.Options version.State |= State.Modified | (State)Column.Path; if (string.IsNullOrEmpty(version.VersionName)) { - version.VersionName = string.Format("{0}_{1}", - Path.GetFileName(Path.GetDirectoryName(qmakeDir)), - Path.GetFileName(qmakeDir)) - .Replace(" ", "_"); + version.VersionName = $"{Path.GetFileName(Path.GetDirectoryName(qmakeDir))}" + + $"_{Path.GetFileName(qmakeDir)}".Replace(" ", "_"); version.State |= State.Modified | (State)Column.VersionName; } diff --git a/QtVsTools.Package/Package/QtHelp.cs b/QtVsTools.Package/Package/QtHelp.cs index e321096c..c8be29cf 100644 --- a/QtVsTools.Package/Package/QtHelp.cs +++ b/QtVsTools.Package/Package/QtHelp.cs @@ -154,10 +154,10 @@ namespace QtVsTools var offline = QtVsToolsPackage.Instance.Options.HelpPreference == SourcePreference.Offline; - var linksForKeyword = string.Format("SELECT d.Title, f.Name, e.Name, " + var linksForKeyword = "SELECT d.Title, f.Name, e.Name, " + "d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, " + "NamespaceTable f WHERE a.FileId=d.FileId AND d.FolderId=e.Id AND " - + "a.NamespaceId=f.Id AND a.Name='{0}'", keyword); + + $"a.NamespaceId=f.Id AND a.Name='{keyword}'"; var links = new Dictionary<string, string>(); var builder = new SQLiteConnectionStringBuilder diff --git a/QtVsTools.Package/Package/QtMsBuildConverter.cs b/QtVsTools.Package/Package/QtMsBuildConverter.cs index f9b9078b..a25b5a8c 100644 --- a/QtVsTools.Package/Package/QtMsBuildConverter.cs +++ b/QtVsTools.Package/Package/QtMsBuildConverter.cs @@ -79,10 +79,10 @@ namespace QtVsTools bool canceled = false; foreach (var projectPath in projectPaths) { if (waitDialog != null) { - waitDialog.Update("Converting solution to Qt/MSBuild..." + Environment.NewLine - + string.Format("Converting project {0}/{1}: {2}...", projCount + 1, - projectPaths.Count, Path.GetFileNameWithoutExtension(projectPath) - ), + waitDialog.Update("Converting solution to Qt/MSBuild..." + + Environment.NewLine + + $"Converting project {projCount + 1}/{projectPaths.Count}: " + + $"{Path.GetFileNameWithoutExtension(projectPath)}...", projectPaths.Count, projCount); if (waitDialog.Canceled) { canceled = true; diff --git a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Program.cs b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Program.cs index cb4c1bbc..99d92f74 100644 --- a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Program.cs +++ b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Program.cs @@ -133,7 +133,7 @@ namespace QtVsTools.Qml.Debug.AD7 public void OutputWriteLine(string msg) { var execFileName = Path.GetFileName(ExecPath); - Engine.OutputWriteLine(string.Format("'{0}' (QML): {1}", execFileName, msg)); + Engine.OutputWriteLine($"'{execFileName}' (QML): {msg}"); } bool IDebuggerEventSink.QueryRuntimeFrozen() diff --git a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Property.cs b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Property.cs index e90145e9..3901fbb0 100644 --- a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Property.cs +++ b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7Property.cs @@ -94,13 +94,13 @@ namespace QtVsTools.Qml.Debug.AD7 static string GetChildKey(string childName) { if (int.TryParse(childName, out int childIndex)) - return string.Format("{0:D9}", childIndex); + return $"{childIndex:D9}"; return childName; } int IDebugProperty2.SetValueAsString(string pszValue, uint dwRadix, uint dwTimeout) { - string expr = string.Format("{0}=({1})", FullName, pszValue); + string expr = $"{FullName}=({pszValue})"; var value = Debugger.Evaluate(FrameNumber, expr); if (value == null || value is JsError) diff --git a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7StackFrame.cs b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7StackFrame.cs index 017472b0..ea3530b3 100644 --- a/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7StackFrame.cs +++ b/QtVsTools.Package/QML/Debugging/AD7/QmlDebugAD7StackFrame.cs @@ -60,7 +60,7 @@ namespace QtVsTools.Qml.Debug.AD7 Engine = context.Engine; Program = context.Program; Debugger = Program.Debugger; - Name = string.Format("{0}@{1}:{2}", name, context.FilePath, context.FileLine + 1); + Name = $"{name}@{context.FilePath}:{context.FileLine + 1}"; FrameNumber = number; Scopes = scopes; InitThread = QtVsToolsPackage.Instance.JoinableTaskFactory.RunAsync(async () => diff --git a/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs b/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs index 7efc9fd6..b41673e8 100644 --- a/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs +++ b/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs @@ -131,7 +131,7 @@ namespace QtVsTools.Qml.Debug public string Path; public static implicit operator string(WslPath wslPath) { - return string.Format(@"{0}:\{1}", wslPath.Drive, wslPath.Path); + return $@"{wslPath.Drive}:\{wslPath.Path}"; } } @@ -192,8 +192,7 @@ namespace QtVsTools.Qml.Debug var activeConfig = project.ConfigurationManager.ActiveConfiguration; if (activeConfig == null) continue; - var activeConfigId = string.Format("{0}|{1}", - activeConfig.ConfigurationName, activeConfig.PlatformName); + var activeConfigId = $"{activeConfig.ConfigurationName}|{activeConfig.PlatformName}"; var vcConfig = vcConfigs.Item(activeConfigId) as VCConfiguration; if (vcConfig == null) continue; @@ -215,7 +214,7 @@ namespace QtVsTools.Qml.Debug if (!sameFile) continue; - OutputWriteLine(string.Format("Debugging project '{0}'...", vcProject.Name)); + OutputWriteLine($"Debugging project '{vcProject.Name}'..."); var qtProject = QtProject.Create(vcProject); if (qtProject == null) { diff --git a/QtVsTools.Package/QML/Debugging/QmlFileSystem.cs b/QtVsTools.Package/QML/Debugging/QmlFileSystem.cs index fb5cc670..53b9c104 100644 --- a/QtVsTools.Package/QML/Debugging/QmlFileSystem.cs +++ b/QtVsTools.Package/QML/Debugging/QmlFileSystem.cs @@ -48,7 +48,7 @@ namespace QtVsTools.Qml.Debug while (!string.IsNullOrEmpty(prefix) && prefix[0] == Path.AltDirectorySeparatorChar) prefix = prefix.Substring(1); - return string.Format("qrc:///{0}{1}", prefix, filePath); + return $"qrc:///{prefix}{filePath}"; } public void RegisterRccFile(string rccFilePath) @@ -100,7 +100,7 @@ namespace QtVsTools.Qml.Debug var qmlFile = new QmlFile { FilePath = Path.Combine(Path.GetDirectoryName(rccFilePath), file.Path), - QrcPath = string.Format("qrc:///{0}{1}", qrcPathPrefix, qrcPath) + QrcPath = $"qrc:///{qrcPathPrefix}{qrcPath}" }; this.files[qmlFile.QrcPath.ToLower()] = qmlFile; @@ -123,7 +123,7 @@ namespace QtVsTools.Qml.Debug while (!string.IsNullOrEmpty(qrcPath) && qrcPath[0] == Path.AltDirectorySeparatorChar) qrcPath = qrcPath.Substring(1); - qrcPath = string.Format("qrc:///{0}", qrcPath); + qrcPath = $"qrc:///{qrcPath}"; if (!files.TryGetValue(qrcPath, out QmlFile file)) return default(QmlFile); diff --git a/QtVsTools.Package/QML/Debugging/V4/Messages/QmlDebugV4JsValue.cs b/QtVsTools.Package/QML/Debugging/V4/Messages/QmlDebugV4JsValue.cs index 4893ba4b..26ac3b90 100644 --- a/QtVsTools.Package/QML/Debugging/V4/Messages/QmlDebugV4JsValue.cs +++ b/QtVsTools.Package/QML/Debugging/V4/Messages/QmlDebugV4JsValue.cs @@ -244,7 +244,7 @@ namespace QtVsTools.Qml.Debug.V4 public override string ToString() { if (Value - Math.Floor(Value) == 0) - return string.Format("{0:0}", Value); + return $"{Value:0}"; return Format(Value); } } diff --git a/QtVsTools.Package/QML/Debugging/V4/QmlDebugV4Client.cs b/QtVsTools.Package/QML/Debugging/V4/QmlDebugV4Client.cs index 0e5d37b3..1314558d 100644 --- a/QtVsTools.Package/QML/Debugging/V4/QmlDebugV4Client.cs +++ b/QtVsTools.Package/QML/Debugging/V4/QmlDebugV4Client.cs @@ -267,8 +267,8 @@ namespace QtVsTools.Qml.Debug.V4 if (messageParams == null) messageParams = new byte[0]; - System.Diagnostics.Debug.WriteLine(string.Format(">> {0} {1}", - messageType, Encoding.UTF8.GetString(messageParams))); + System.Diagnostics.Debug.WriteLine( + $">> {messageType} {Encoding.UTF8.GetString(messageParams)}"); return NativeMethods.DebugClientSendMessage(client, messageTypeData, messageTypeData.Length, @@ -320,8 +320,8 @@ namespace QtVsTools.Qml.Debug.V4 return; var messageType = Encoding.UTF8.GetString(messageTypeData); - System.Diagnostics.Debug.WriteLine(string.Format("<< {0} {1}", - messageType, Encoding.UTF8.GetString(messageParamsData))); + System.Diagnostics.Debug.WriteLine( + $"<< {messageType} {Encoding.UTF8.GetString(messageParamsData)}"); sink.NotifyMessageReceived(this, messageType, messageParamsData); } diff --git a/QtVsTools.Package/QtMsBuild/QtProjectIntelliSense.cs b/QtVsTools.Package/QtMsBuild/QtProjectIntelliSense.cs index 5fdc29a4..85c42ba9 100644 --- a/QtVsTools.Package/QtMsBuild/QtProjectIntelliSense.cs +++ b/QtVsTools.Package/QtMsBuild/QtProjectIntelliSense.cs @@ -31,10 +31,9 @@ namespace QtVsTools.QtMsBuild return; if (QtVsToolsPackage.Instance.Options.BuildDebugInformation) { - Messages.Print(string.Format( - "{0:HH:mm:ss.FFF} QtProjectIntellisense({1}): Refreshing: [{2}] {3}", - DateTime.Now, Thread.CurrentThread.ManagedThreadId, - (configId != null) ? configId : "(all configs)", project.FullName)); + Messages.Print($"{DateTime.Now:HH:mm:ss.FFF} " + + $"QtProjectIntellisense({Thread.CurrentThread.ManagedThreadId}): " + + $"Refreshing: [{configId ?? "(all configs)"}] {project.FullName}"); } string projectPath = project.FullName; _ = Task.Run(() => RefreshAsync(project, projectPath, configId, selectedFiles, false)); diff --git a/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs b/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs index ed8582e4..e49e7b5c 100644 --- a/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs +++ b/QtVsTools.Package/QtMsBuild/QtProjectTracker.cs @@ -164,10 +164,9 @@ namespace QtVsTools.QtMsBuild UpdateInitStatus(p += d); configProject.ProjectUnloading += OnProjectUnloadingAsync; if (QtVsToolsPackage.Instance.Options.BuildDebugInformation) { - Messages.Print(string.Format( - "{0:HH:mm:ss.FFF} QtProjectTracker({1}): Started tracking [{2}] {3}", - DateTime.Now, Thread.CurrentThread.ManagedThreadId, - config.Name, ProjectPath)); + Messages.Print($"{DateTime.Now:HH:mm:ss.FFF} " + + $"QtProjectTracker({Thread.CurrentThread.ManagedThreadId}): " + + $"Started tracking [{config.Name}] {ProjectPath}"); } UpdateInitStatus(p += d); } @@ -177,11 +176,9 @@ namespace QtVsTools.QtMsBuild { if (sender is ConfiguredProject project) { if (QtVsToolsPackage.Instance.Options.BuildDebugInformation) { - Messages.Print(string.Format( - "{0:HH:mm:ss.FFF} QtProjectTracker: Stopped tracking [{1}] {2}", - DateTime.Now, - project.ProjectConfiguration.Name, - project.UnconfiguredProject.FullPath)); + Messages.Print($"{DateTime.Now:HH:mm:ss.FFF} QtProjectTracker: " + + $"Stopped tracking [{project.ProjectConfiguration.Name}] " + + $"{project.UnconfiguredProject.FullPath}"); } lock (CriticalSection) { @@ -208,8 +205,7 @@ namespace QtVsTools.QtMsBuild }, new TaskProgressData { - ProgressText = string.Format("{0} ({1} projects remaining)", - Project.Name, InitQueue.Count), + ProgressText = $"{Project.Name} ({InitQueue.Count} projects remaining)", CanBeCanceled = true, PercentComplete = 0 }) @@ -229,8 +225,8 @@ namespace QtVsTools.QtMsBuild try { InitStatus.Progress.Report(new TaskProgressData { - ProgressText = string.Format("{0} ({1} project(s) remaining)", - Path.GetFileNameWithoutExtension(ProjectPath), InitQueue.Count), + ProgressText = $"{Path.GetFileNameWithoutExtension(ProjectPath)} " + + $"({InitQueue.Count} project(s) remaining)", CanBeCanceled = true, PercentComplete = percentComplete }); diff --git a/QtVsTools.RegExpr/parser/ParseTree.cs b/QtVsTools.RegExpr/parser/ParseTree.cs index 919d2b8a..b8510753 100644 --- a/QtVsTools.RegExpr/parser/ParseTree.cs +++ b/QtVsTools.RegExpr/parser/ParseTree.cs @@ -79,13 +79,13 @@ namespace QtVsTools.SyntaxAnalysis { if (CaptureId == KeyRoot) return KeyRoot; - return string.Format("{0}:{1}:{2}", CaptureId, Begin, End); + return $"{CaptureId}:{Begin}:{End}"; } } public override string ToString() { - return string.Format("{0}[{1}]", TokenId, Value); + return $"{TokenId}[{Value}]"; } public static implicit operator ParseTree(Node node) diff --git a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs index 9d17d198..d82ea2bc 100644 --- a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs +++ b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs @@ -128,12 +128,10 @@ namespace QtVsTools.Wizards.ItemWizard var pro = HelperFunctions.GetSelectedQtProject(Dte); if (pro != null) { var qtProject = QtProject.Create(pro); - if (qtProject != null && qtProject.UsesPrecompiledHeaders()) { - include.AppendLine(string.Format("#include \"{0}\"", qtProject - .GetPrecompiledHeaderThrough())); - } + if (qtProject != null && qtProject.UsesPrecompiledHeaders()) + include.AppendLine($"#include \"{qtProject.GetPrecompiledHeaderThrough()}\""); } - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewQtItem.Include] = FormatParam(include); if (!string.IsNullOrEmpty(baseClass)) { diff --git a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs index fbfc7f82..731c4ff6 100644 --- a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs +++ b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs @@ -148,19 +148,17 @@ namespace QtVsTools.Wizards.ItemWizard var pro = HelperFunctions.GetSelectedQtProject(Dte); if (pro != null) { var qtProject = QtProject.Create(pro); - if (qtProject != null && qtProject.UsesPrecompiledHeaders()) { - include.AppendLine(string.Format("#include \"{0}\"", qtProject - .GetPrecompiledHeaderThrough())); - } + if (qtProject != null && qtProject.UsesPrecompiledHeaders()) + include.AppendLine($"#include \"{qtProject.GetPrecompiledHeaderThrough()}\""); } - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewWidgetsItem.Include] = FormatParam(include); Parameter[NewWidgetsItem.QObject] = WizardData.InsertQObjectMacro ? "\r\n Q_OBJECT\r\n" : ""; - Parameter[NewWidgetsItem.UiHeaderName] = string.Format("ui_{0}.h", - Path.GetFileNameWithoutExtension(WizardData.UiFile)); + Parameter[NewWidgetsItem.UiHeaderName] = + $"ui_{Path.GetFileNameWithoutExtension(WizardData.UiFile)}.h"; if (WizardData.BaseClass == "QMainWindow") { Parameter[NewWidgetsItem.CentralWidget] = FormatParam( @@ -173,25 +171,19 @@ namespace QtVsTools.Wizards.ItemWizard switch (WizardData.UiClassInclusion) { case UiClassInclusion.MemberPointer: - Parameter[NewWidgetsItem.ForwardDeclClass] = - string.Format( - "\r\nQT_BEGIN_NAMESPACE\r\n" - + "namespace Ui {{ class {0}Class; }};\r\n" - + "QT_END_NAMESPACE\r\n", className - ); + Parameter[NewWidgetsItem.ForwardDeclClass] = "\r\nQT_BEGIN_NAMESPACE\r\n" + + $"namespace Ui {{ class {className}Class; }};\r\n" + "QT_END_NAMESPACE\r\n"; Parameter[Meta.Asterisk] = "*"; Parameter[Meta.Operator] = "->"; - Parameter[Meta.New] = string.Format("\r\n , {0}(new Ui::{1}Class())", - Parameter[NewWidgetsItem.Member], className); - Parameter[Meta.Delete] = string.Format("\r\n delete {0};\r\n", - Parameter[NewWidgetsItem.Member]); + Parameter[Meta.New] = + $"\r\n , {Parameter[NewWidgetsItem.Member]}(new Ui::{className}Class())"; + Parameter[Meta.Delete] = $"\r\n delete {Parameter[NewWidgetsItem.Member]};\r\n"; goto case UiClassInclusion.Member; case UiClassInclusion.Member: - Parameter[NewWidgetsItem.UiClassName] = string.Format("Ui::{0}Class", className); + Parameter[NewWidgetsItem.UiClassName] = $"Ui::{className}Class"; break; case UiClassInclusion.MultipleInheritance: - Parameter[NewWidgetsItem.MultipleInheritance] = - string.Format(", public Ui::{0}Class", className); + Parameter[NewWidgetsItem.MultipleInheritance] = $", public Ui::{className}Class"; Parameter[NewWidgetsItem.Member] = ""; Parameter[Meta.Operator] = ""; Parameter[Meta.Semicolon] = ""; diff --git a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs index 7f11e9f7..bddaf5b6 100644 --- a/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs +++ b/QtVsTools.Wizards/ProjectWizard/ConfigPage.xaml.cs @@ -215,7 +215,7 @@ namespace QtVsTools.Wizards.ProjectWizard NextButton.IsEnabled = false; FinishButton.IsEnabled = false; } else if (currentConfigs // "$(Configuration)|$(Platform)" must be unique - .GroupBy((Config c) => string.Format("{0}|{1}", c.Name, c.Platform)) + .GroupBy((Config c) => $"{c.Name}|{c.Platform}") .Where((IGrouping<string, Config> g) => g.Count() > 1) .Any()) { ErrorMsg.Content = "(Configuration, Platform) must be unique"; @@ -408,12 +408,12 @@ namespace QtVsTools.Wizards.ProjectWizard if (sender is CheckBox checkBox && GetBinding(checkBox) is Config config) { config.IsDebug = checkBox.IsChecked ?? false; if (config.IsDebug && config.Name.EndsWith("Release")) { - config.Name = string.Format("{0}Debug", - config.Name.Substring(0, config.Name.Length - "Release".Length)); + config.Name = + $"{config.Name.Substring(0, config.Name.Length - "Release".Length)}Debug"; ConfigTable.Items.Refresh(); } else if (!config.IsDebug && config.Name.EndsWith("Debug")) { - config.Name = string.Format("{0}Release", - config.Name.Substring(0, config.Name.Length - "Debug".Length)); + config.Name = + $"{config.Name.Substring(0, config.Name.Length - "Debug".Length)}Release"; ConfigTable.Items.Refresh(); } Validate(); diff --git a/QtVsTools.Wizards/ProjectWizard/Console/ConsoleWizard.cs b/QtVsTools.Wizards/ProjectWizard/Console/ConsoleWizard.cs index 454cc20b..e4416b51 100644 --- a/QtVsTools.Wizards/ProjectWizard/Console/ConsoleWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/Console/ConsoleWizard.cs @@ -55,9 +55,8 @@ namespace QtVsTools.Wizards.ProjectWizard { foreach (var config in configs) { if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { - return string.Format( - "Console Application project not available for the '{0}' target.", - config.Target); + return "Console Application project not available for the " + + $"'{config.Target}' target."; } } return string.Empty; diff --git a/QtVsTools.Wizards/ProjectWizard/Designer/DesignerWizard.cs b/QtVsTools.Wizards/ProjectWizard/Designer/DesignerWizard.cs index 3feced21..c89ee6bb 100644 --- a/QtVsTools.Wizards/ProjectWizard/Designer/DesignerWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/Designer/DesignerWizard.cs @@ -94,9 +94,8 @@ namespace QtVsTools.Wizards.ProjectWizard { foreach (var config in configs) { if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { - return string.Format( - "Custom Designer Widget project not available for the '{0}' target.", - config.Target); + return "Custom Designer Widget project not available for the " + + $"'{config.Target}' target."; } } return string.Empty; @@ -130,17 +129,16 @@ namespace QtVsTools.Wizards.ProjectWizard var include = new StringBuilder(); if (UsePrecompiledHeaders) - include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{PrecompiledHeader.Include}\""); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewClass.Include] = FormatParam(include); Parameter[NewDesignerPlugin.ClassName] = WizardData.PluginClass; Parameter[NewDesignerPlugin.HeaderFileName] = WizardData.PluginHeaderFile; Parameter[NewDesignerPlugin.SourceFileName] = WizardData.PluginSourceFile; Parameter[NewDesignerPlugin.JsonFileName] = WizardData.PluginClass.ToLower() + ".json"; - Parameter[NewDesignerPlugin.ObjectName] = string.Format("{0}{1}", - WizardData.ClassName[0], - WizardData.ClassName.Substring(1)); + Parameter[NewDesignerPlugin.ObjectName] = + $"{WizardData.ClassName[0]}{WizardData.ClassName.Substring(1)}"; } protected override void OnProjectGenerated(Project project) diff --git a/QtVsTools.Wizards/ProjectWizard/Gui/GuiWizard.cs b/QtVsTools.Wizards/ProjectWizard/Gui/GuiWizard.cs index 76592c2a..b0e1422e 100644 --- a/QtVsTools.Wizards/ProjectWizard/Gui/GuiWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/Gui/GuiWizard.cs @@ -198,12 +198,12 @@ namespace QtVsTools.Wizards.ProjectWizard var include = new StringBuilder(); if (UsePrecompiledHeaders) - include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{PrecompiledHeader.Include}\""); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewClass.Include] = FormatParam(include); - Parameter[NewGuiProject.UiHeaderName] = string.Format("ui_{0}.h", - Path.GetFileNameWithoutExtension(WizardData.UiFile)); + Parameter[NewGuiProject.UiHeaderName] = + $"ui_{Path.GetFileNameWithoutExtension(WizardData.UiFile)}.h"; Parameter[NewGuiProject.QrcFileName] = WizardData.QrcFile; if (WizardData.BaseClass == "QMainWindow") { @@ -247,8 +247,7 @@ namespace QtVsTools.Wizards.ProjectWizard Filter = "Resource Files" }); winRcFile.AppendLine( - string.Format("IDI_ICON1\t\tICON\t\tDISCARDABLE\t\"{0}.ico\"", - /*{0}*/ Parameter[NewProject.SafeName])); + $"IDI_ICON1\t\tICON\t\tDISCARDABLE\t\"{Parameter[NewProject.SafeName]}.ico\""); } } @@ -268,25 +267,19 @@ namespace QtVsTools.Wizards.ProjectWizard switch (WizardData.UiClassInclusion) { case UiClassInclusion.MemberPointer: - Parameter[NewGuiProject.ForwardDeclClass] = - string.Format( - "\r\nQT_BEGIN_NAMESPACE\r\n" - + "namespace Ui {{ class {0}Class; }};\r\n" - + "QT_END_NAMESPACE\r\n", className - ); + Parameter[NewGuiProject.ForwardDeclClass] = "\r\nQT_BEGIN_NAMESPACE\r\n" + + $"namespace Ui {{ class {className}Class; }};\r\n" + "QT_END_NAMESPACE\r\n"; Parameter[Meta.Asterisk] = "*"; Parameter[Meta.Operator] = "->"; - Parameter[Meta.New] = string.Format("\r\n , {0}(new Ui::{1}Class())", - Parameter[NewGuiProject.Member], className); - Parameter[Meta.Delete] = string.Format("\r\n delete {0};\r\n", - Parameter[NewGuiProject.Member]); + Parameter[Meta.New] = + $"\r\n , {Parameter[NewGuiProject.Member]}(new Ui::{className}Class())"; + Parameter[Meta.Delete] = $"\r\n delete {Parameter[NewGuiProject.Member]};\r\n"; goto case UiClassInclusion.Member; case UiClassInclusion.Member: - Parameter[NewGuiProject.UiClassName] = string.Format("Ui::{0}Class", className); + Parameter[NewGuiProject.UiClassName] = $"Ui::{className}Class"; break; case UiClassInclusion.MultipleInheritance: - Parameter[NewGuiProject.MultipleInheritance] = - string.Format(", public Ui::{0}Class", className); + Parameter[NewGuiProject.MultipleInheritance] = $", public Ui::{className}Class"; Parameter[NewGuiProject.Member] = ""; Parameter[Meta.Operator] = ""; Parameter[Meta.Semicolon] = ""; @@ -315,8 +308,7 @@ namespace QtVsTools.Wizards.ProjectWizard var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp"); Directory.CreateDirectory(qmakeTmpDir); - var dummyPro = Path.Combine(qmakeTmpDir, - string.Format("{0}.pro", Parameter[NewProject.SafeName])); + var dummyPro = Path.Combine(qmakeTmpDir, $"{Parameter[NewProject.SafeName]}.pro"); File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n"); var qmake = new QMakeImport(configWinRT.QtVersion, dummyPro); diff --git a/QtVsTools.Wizards/ProjectWizard/Library/LibraryWizard.cs b/QtVsTools.Wizards/ProjectWizard/Library/LibraryWizard.cs index f39bc334..15a0e78b 100644 --- a/QtVsTools.Wizards/ProjectWizard/Library/LibraryWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/Library/LibraryWizard.cs @@ -102,8 +102,8 @@ namespace QtVsTools.Wizards.ProjectWizard var include = new StringBuilder(); if (UsePrecompiledHeaders) - include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{PrecompiledHeader.Include}\""); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewLibClass.Include] = FormatParam(include); var safeprojectname = Parameter[NewProject.SafeName]; diff --git a/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs b/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs index 5a1ef16f..5ee76c89 100644 --- a/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/ProjectTemplateWizard.cs @@ -146,7 +146,7 @@ namespace QtVsTools.Wizards.ProjectWizard string ParamKey(Enum param) { - return string.Format("${0}$", param.Cast<string>()); + return $"${param.Cast<string>()}$"; } public string this[Enum param] diff --git a/QtVsTools.Wizards/ProjectWizard/Server/ServerWizard.cs b/QtVsTools.Wizards/ProjectWizard/Server/ServerWizard.cs index 1200867b..821ad7a8 100644 --- a/QtVsTools.Wizards/ProjectWizard/Server/ServerWizard.cs +++ b/QtVsTools.Wizards/ProjectWizard/Server/ServerWizard.cs @@ -88,11 +88,8 @@ namespace QtVsTools.Wizards.ProjectWizard string ValidateConfigsForActiveQtServer(IEnumerable<IWizardConfiguration> configs) { foreach (var config in configs) { - if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { - return string.Format( - "ActiveQt Server project not available for the '{0}' target.", - config.Target); - } + if (config.Target.EqualTo(ProjectTargets.WindowsStore)) + return $"ActiveQt Server project not available for the '{config.Target}' target."; } return string.Empty; } @@ -126,12 +123,12 @@ namespace QtVsTools.Wizards.ProjectWizard var include = new StringBuilder(); if (UsePrecompiledHeaders) - include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); - include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + include.AppendLine($"#include \"{PrecompiledHeader.Include}\""); + include.AppendLine($"#include \"{WizardData.ClassHeaderFile}\""); Parameter[NewClass.Include] = FormatParam(include); - Parameter[NewActiveQtProject.UiHeaderName] = string.Format("ui_{0}.h", - Path.GetFileNameWithoutExtension(WizardData.UiFile)); + Parameter[NewActiveQtProject.UiHeaderName] = + $"ui_{Path.GetFileNameWithoutExtension(WizardData.UiFile)}.h"; Parameter[NewActiveQtProject.Name] = WizardData.LowerCaseFileNames ? Parameter[NewProject.SafeName].ToLower() diff --git a/Tests/Test_QtVsTools.RegExpr/Test_XmlIntParser.cs b/Tests/Test_QtVsTools.RegExpr/Test_XmlIntParser.cs index 91a0e6d2..f5795b65 100644 --- a/Tests/Test_QtVsTools.RegExpr/Test_XmlIntParser.cs +++ b/Tests/Test_QtVsTools.RegExpr/Test_XmlIntParser.cs @@ -171,7 +171,7 @@ namespace QtVsTools.Test.RegExpr Create(IdTagName, (string name) => name), Error( (string tag, string tagName) => tagName != tag, - (tag, tagName) => string.Format("Expected {0}, found {1}", tagName, tag)), + (tag, tagName) => $"Expected {tagName}, found {tag}"), Create( (string tag, string value) => value.StartsWith("="), (tag, value) => tag + value), |