aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Core
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2022-02-08 15:44:38 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2022-02-09 18:54:53 +0000
commit134748d4634c5005fa9e4e97994c921660388b01 (patch)
tree9e0aad1378967cf46a8afcc9842d2028c2f331da /QtVsTools.Core
parent6257be9d2b29a9f9dc7535179233ab3c6b46bf60 (diff)
Use pattern matching
Change-Id: I49c5c7988a08affc42455355926cc0e442e0fe5f Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Diffstat (limited to 'QtVsTools.Core')
-rw-r--r--QtVsTools.Core/HelperFunctions.cs40
-rw-r--r--QtVsTools.Core/MsBuildProject.cs3
-rw-r--r--QtVsTools.Core/ProjectExporter.cs8
-rw-r--r--QtVsTools.Core/QtProject.cs42
4 files changed, 36 insertions, 57 deletions
diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs
index 12a4933f..19dcba65 100644
--- a/QtVsTools.Core/HelperFunctions.cs
+++ b/QtVsTools.Core/HelperFunctions.cs
@@ -394,21 +394,17 @@ namespace QtVsTools.Core
/// <returns></returns>
public static VCCustomBuildTool GetCustomBuildTool(VCFileConfiguration config)
{
- var file = config.File as VCFile;
- if (file == null || file.ItemType != "CustomBuild")
- return null;
-
- var tool = config.Tool as VCCustomBuildTool;
- if (tool == null)
- return null;
-
- try {
- // TODO: The return value is not used at all?
- var cmdLine = tool.CommandLine;
- } catch {
- return null;
+ if (config.File is VCFile file
+ && file.ItemType == "CustomBuild"
+ && config.Tool is VCCustomBuildTool tool) {
+ try {
+ _ = tool.CommandLine;
+ } catch {
+ return null;
+ }
+ return tool;
}
- return tool;
+ return null;
}
/// <summary>
@@ -1098,8 +1094,8 @@ namespace QtVsTools.Core
return null;
// don't handle multiple selection... use the first one
- if (prjs.GetValue(0) is Project)
- return (Project)prjs.GetValue(0);
+ if (prjs.GetValue(0) is Project project)
+ return project;
return null;
}
@@ -1458,12 +1454,10 @@ namespace QtVsTools.Core
VCProject vcProj = null;
VCFile vcFile = null;
string configName = "", platformName = "";
- var vcConfig = config as VCConfiguration;
- if (vcConfig != null) {
+ if (config is VCConfiguration vcConfig) {
vcProj = vcConfig.project as VCProject;
configName = vcConfig.ConfigurationName;
- var vcPlatform = vcConfig.Platform as VCPlatform;
- if (vcPlatform != null)
+ if (vcConfig.Platform is VCPlatform vcPlatform)
platformName = vcPlatform.Name;
try {
expanded = vcConfig.Evaluate(expanded);
@@ -1475,11 +1469,9 @@ namespace QtVsTools.Core
vcFile = vcFileConfig.File as VCFile;
if (vcFile != null)
vcProj = vcFile.project as VCProject;
- var vcProjConfig = vcFileConfig.ProjectConfiguration as VCConfiguration;
- if (vcProjConfig != null) {
+ if (vcFileConfig.ProjectConfiguration is VCConfiguration vcProjConfig) {
configName = vcProjConfig.ConfigurationName;
- var vcPlatform = vcProjConfig.Platform as VCPlatform;
- if (vcPlatform != null)
+ if (vcProjConfig.Platform is VCPlatform vcPlatform)
platformName = vcPlatform.Name;
}
try {
diff --git a/QtVsTools.Core/MsBuildProject.cs b/QtVsTools.Core/MsBuildProject.cs
index 533acb16..2efdad5a 100644
--- a/QtVsTools.Core/MsBuildProject.cs
+++ b/QtVsTools.Core/MsBuildProject.cs
@@ -961,8 +961,7 @@ namespace QtVsTools.Core
evaluator.Properties.Add(configProp.Name.LocalName, (string)configProp);
if (!qtMsBuild.SetCommandLine(itemType, item, commandLine, evaluator)) {
int lineNumber = 1;
- var errorLine = row.command as IXmlLineInfo;
- if (errorLine != null && errorLine.HasLineInfo())
+ if (row.command is IXmlLineInfo errorLine && errorLine.HasLineInfo())
lineNumber = errorLine.LineNumber;
Messages.Print(string.Format(
diff --git a/QtVsTools.Core/ProjectExporter.cs b/QtVsTools.Core/ProjectExporter.cs
index 757f1f3a..ff737eea 100644
--- a/QtVsTools.Core/ProjectExporter.cs
+++ b/QtVsTools.Core/ProjectExporter.cs
@@ -199,8 +199,7 @@ namespace QtVsTools.Core
if (config.ConfigurationType == ConfigurationTypes.typeStaticLibrary)
option.List.Add("staticlib");
if (linker != null) {
- var linkerRule = linker as IVCRulePropertyStorage;
- var generateDebugInformation = (linkerRule != null) ?
+ var generateDebugInformation = (linker is IVCRulePropertyStorage linkerRule) ?
linkerRule.GetUnevaluatedPropertyValue("GenerateDebugInformation") : null;
if (generateDebugInformation != "false")
option.List.Add("debug");
@@ -448,10 +447,7 @@ namespace QtVsTools.Core
if (!d.StartsWith("$(qtdir)\\include", StringComparison.OrdinalIgnoreCase) &&
!d.StartsWith(qtDir + "\\include", StringComparison.OrdinalIgnoreCase) &&
!d.EndsWith("win32-msvc2005", StringComparison.OrdinalIgnoreCase)) {
-
- var vcConfig = project.ConfigurationManager.ActiveConfiguration.Object
- as VCConfiguration;
- if (vcConfig != null)
+ if (project.ConfigurationManager.ActiveConfiguration.Object is VCConfiguration vcConfig)
HelperFunctions.ExpandString(ref d, vcConfig);
if (HelperFunctions.IsAbsoluteFilePath(d))
d = HelperFunctions.GetRelativePath(project.FullName, d);
diff --git a/QtVsTools.Core/QtProject.cs b/QtVsTools.Core/QtProject.cs
index 5965635e..51e649c1 100644
--- a/QtVsTools.Core/QtProject.cs
+++ b/QtVsTools.Core/QtProject.cs
@@ -558,8 +558,7 @@ namespace QtVsTools.Core
string description,
string outputFile)
{
- var file = config.File as VCFile;
- if (file != null)
+ if (config.File is VCFile file)
file.ItemType = QtUic.ItemTypeName;
qtMsBuild.SetItemProperty(config, QtUic.Property.ExecutionDescription, description);
qtMsBuild.SetItemProperty(config, QtUic.Property.OutputFile, outputFile);
@@ -684,15 +683,15 @@ namespace QtVsTools.Core
public string GetDefines(VCFileConfiguration conf)
{
var defines = string.Empty;
- var propsFile = conf.Tool as IVCRulePropertyStorage;
- var projectConfig = conf.ProjectConfiguration as VCConfiguration;
- var propsProject = projectConfig.Rules.Item("CL") as IVCRulePropertyStorage;
- if (propsFile != null) {
+ if (conf.Tool is IVCRulePropertyStorage propsFile) {
try {
defines = propsFile.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
} catch { }
}
- if (string.IsNullOrEmpty(defines) && propsProject != null) {
+
+ var projectConfig = conf.ProjectConfiguration as VCConfiguration;
+ if (string.IsNullOrEmpty(defines)
+ && projectConfig?.Rules.Item("CL") is IVCRulePropertyStorage propsProject) {
try {
defines = propsProject.GetUnevaluatedPropertyValue("PreprocessorDefinitions");
} catch { }
@@ -734,8 +733,7 @@ namespace QtVsTools.Core
var projectConfig = conf.ProjectConfiguration as VCConfiguration;
includeList.AddRange(GetIncludesFromCompilerTool(CompilerToolWrapper.Create(projectConfig)));
- var propertySheets = projectConfig.PropertySheets as IVCCollection;
- if (propertySheets != null) {
+ if (projectConfig.PropertySheets is IVCCollection propertySheets) {
foreach (VCPropertySheet sheet in propertySheets)
includeList.AddRange(GetIncludesFromPropertySheet(sheet));
}
@@ -756,8 +754,7 @@ namespace QtVsTools.Core
private List<string> GetIncludesFromPropertySheet(VCPropertySheet sheet)
{
var includeList = GetIncludesFromCompilerTool(CompilerToolWrapper.Create(sheet));
- var propertySheets = sheet.PropertySheets as IVCCollection;
- if (propertySheets != null) {
+ if (sheet.PropertySheets is IVCCollection propertySheets) {
foreach (VCPropertySheet subSheet in propertySheets)
includeList.AddRange(GetIncludesFromPropertySheet(subSheet));
}
@@ -1225,8 +1222,7 @@ namespace QtVsTools.Core
File.WriteAllText(cbtFullPath, string.Format(
"This is a dummy file needed to create {0}", mocFileName));
file = AddFileInSubfilter(Filters.GeneratedFiles(), null, cbtFullPath, true);
- var mocFileItem = file.Object as ProjectItem;
- if (mocFileItem != null)
+ if (file.Object is ProjectItem mocFileItem)
HelperFunctions.EnsureCustomBuildToolAvailable(mocFileItem);
}
@@ -1381,8 +1377,7 @@ namespace QtVsTools.Core
string nameOnly,
string qrcCppFile)
{
- var file = vfc.File as VCFile;
- if (file != null)
+ if (vfc.File is VCFile file)
file.ItemType = QtRcc.ItemTypeName;
qtMsBuild.SetItemProperty(vfc,
QtRcc.Property.ExecutionDescription, "Rcc'ing " + ProjectMacros.FileName + "...");
@@ -1559,8 +1554,7 @@ namespace QtVsTools.Core
List<VCFile> GetCppMocFiles(VCFile cppFile)
{
List<VCFile> mocFiles = new List<VCFile>();
- var vcProj = cppFile.project as VCProject;
- if (vcProj != null) {
+ if (cppFile.project is VCProject vcProj) {
mocFiles.AddRange(from VCFile vcFile
in (IVCCollection)vcProj.Files
where vcFile.ItemType == "CustomBuild"
@@ -1589,8 +1583,7 @@ namespace QtVsTools.Core
if (!IsQtMsBuildEnabled())
return File.Exists(Path.ChangeExtension(cppFile.FullPath, ".cbt"));
- var vcProj = cppFile.project as VCProject;
- if (vcProj != null) {
+ if (cppFile.project is VCProject vcProj) {
foreach (VCFile vcFile in (IVCCollection)vcProj.Files) {
if (vcFile.ItemType == "CustomBuild") {
if (IsCppMocFileCustomBuild(vcProj, vcFile, cppFile))
@@ -3252,8 +3245,7 @@ namespace QtVsTools.Core
debuggerEnv = propertyAccess.GetPropertyValue(
"LocalDebuggerEnvironment", cur_solution, "UserFile");
if (!string.IsNullOrEmpty(debuggerEnv)) {
- var debugSettings = conf.DebugSettings as VCDebugSettings;
- if (debugSettings != null) {
+ if (conf.DebugSettings is VCDebugSettings debugSettings) {
//Get original value without expanded properties
debuggerEnv = debugSettings.Environment;
}
@@ -3632,10 +3624,10 @@ namespace QtVsTools.Core
{
if (propertyStorage == null)
return null;
- if (propertyStorage is VCFileConfiguration)
- return GetParentProject(propertyStorage as VCFileConfiguration);
- else if (propertyStorage is VCConfiguration)
- return GetParentProject(propertyStorage as VCConfiguration);
+ if (propertyStorage is VCFileConfiguration configuration)
+ return GetParentProject(configuration);
+ else if (propertyStorage is VCConfiguration storage)
+ return GetParentProject(storage);
return null;
}