diff --git a/global.json b/global.json index 76b8d414..5c10df40 100644 --- a/global.json +++ b/global.json @@ -1,8 +1,8 @@ { "sdk": { - "version": "6.0.301" + "version": "6.0.401" }, "msbuild-sdks": { "Microsoft.Build.NoTargets": "3.2.9" } -} \ No newline at end of file +} diff --git a/src/Microsoft.InsightsGenerator/RulesEngine.cs b/src/Microsoft.InsightsGenerator/RulesEngine.cs index 2c333018..5a264e2a 100644 --- a/src/Microsoft.InsightsGenerator/RulesEngine.cs +++ b/src/Microsoft.InsightsGenerator/RulesEngine.cs @@ -61,10 +61,7 @@ namespace Microsoft.InsightsGenerator public static string FindMatchedTemplate(List> singleHashHeaders, DataArray columnInfo) { var resultTemplate = new StringBuilder(); - if (Templates == null) - { - Templates = GetTemplates(); - } + Templates ??= GetTemplates(); var headersWithSingleHash = GetTopHeadersWithHash(singleHashHeaders); foreach (var template in Templates) diff --git a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs index 6fee2c02..54b5aba2 100644 --- a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs @@ -60,10 +60,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection { get { - if (lockedDatabaseManager == null) - { - lockedDatabaseManager = DatabaseLocksManager.Instance; - } + lockedDatabaseManager ??= DatabaseLocksManager.Instance; return lockedDatabaseManager; } set diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/LanguageService.cs index 3403c2d1..1e20e415 100644 --- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/LanguageService.cs @@ -151,10 +151,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices { get { - if (workspaceServiceInstance == null) - { - workspaceServiceInstance = WorkspaceService.Instance; - } + workspaceServiceInstance ??= WorkspaceService.Instance; return workspaceServiceInstance; } set @@ -167,10 +164,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices { get { - if (this.serviceHostInstance == null) - { - this.serviceHostInstance = ServiceHost.Instance; - } + this.serviceHostInstance ??= ServiceHost.Instance; return this.serviceHostInstance; } set @@ -872,10 +866,8 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices } // if there are no completions then provide the default list - if (resultCompletionItems == null) // this is the getting default keyword option when its not connected - { - resultCompletionItems = DataSourceFactory.GetDefaultAutoComplete(DataSourceType.Kusto, scriptDocumentInfo, textDocumentPosition.Position); - } + // this is the getting default keyword option when its not connected + resultCompletionItems ??= DataSourceFactory.GetDefaultAutoComplete(DataSourceType.Kusto, scriptDocumentInfo, textDocumentPosition.Position); return resultCompletionItems; } diff --git a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/DataSourceModel/NodePathGenerator.cs b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/DataSourceModel/NodePathGenerator.cs index f487089e..57bf85c6 100644 --- a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/DataSourceModel/NodePathGenerator.cs +++ b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/DataSourceModel/NodePathGenerator.cs @@ -70,10 +70,7 @@ namespace Microsoft.Kusto.ServiceLayer.ObjectExplorer.DataSourceModel path = schema + "." + path; } - if (path == null) - { - path = ""; - } + path ??= ""; foreach (var matchingNode in matchingNodes) { diff --git a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs index 6f178a93..89de783a 100644 --- a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs +++ b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs @@ -262,10 +262,7 @@ namespace Microsoft.Kusto.ServiceLayer.ObjectExplorer internal async Task HandleFindNodesRequest(FindNodesParams findNodesParams, RequestContext context) { var foundNodes = FindNodes(findNodesParams.SessionId, findNodesParams.Type, findNodesParams.Schema, findNodesParams.Name, findNodesParams.Database, findNodesParams.ParentObjectNames); - if (foundNodes == null) - { - foundNodes = new List(); - } + foundNodes ??= new List(); await context.SendResult(new FindNodesResponse { Nodes = foundNodes.Select(node => node.ToNodeInfo()).ToList() }); } diff --git a/src/Microsoft.Kusto.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs b/src/Microsoft.Kusto.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs index 1164c153..b4d4c91d 100644 --- a/src/Microsoft.Kusto.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs +++ b/src/Microsoft.Kusto.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs @@ -171,9 +171,9 @@ namespace Microsoft.Kusto.ServiceLayer.QueryExecution.DataStorage AddCell((string)o); break; default: - if (o is TimeSpan) //TimeSpan doesn't have TypeCode + if (o is TimeSpan span) //TimeSpan doesn't have TypeCode { - AddCell((TimeSpan)o); + AddCell(span); break; } AddCell(dbCellValue.DisplayValue); @@ -510,10 +510,7 @@ namespace Microsoft.Kusto.ServiceLayer.QueryExecution.DataStorage public ExcelSheet AddSheet(string sheetName = null) { string sheetFileName = "sheet" + (sheetNames.Count + 1); - if (sheetName == null) - { - sheetName = sheetFileName; - } + sheetName ??= sheetFileName; EnsureValidSheetName(sheetName); sheetNames.Add(sheetName); diff --git a/src/Microsoft.Kusto.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.Kusto.ServiceLayer/QueryExecution/QueryExecutionService.cs index 6c7e7a40..2fdc2e90 100644 --- a/src/Microsoft.Kusto.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.Kusto.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -68,13 +68,10 @@ namespace Microsoft.Kusto.ServiceLayer.QueryExecution { get { - if (BufferFileStreamFactory == null) + BufferFileStreamFactory ??= new ServiceBufferFileStreamFactory { - BufferFileStreamFactory = new ServiceBufferFileStreamFactory - { - ExecutionSettings = Settings.QueryExecutionSettings - }; - } + ExecutionSettings = Settings.QueryExecutionSettings + }; return BufferFileStreamFactory; } } diff --git a/src/Microsoft.Kusto.ServiceLayer/SqlContext/SqlToolsSettings.cs b/src/Microsoft.Kusto.ServiceLayer/SqlContext/SqlToolsSettings.cs index 57addf68..f32ea9bc 100644 --- a/src/Microsoft.Kusto.ServiceLayer/SqlContext/SqlToolsSettings.cs +++ b/src/Microsoft.Kusto.ServiceLayer/SqlContext/SqlToolsSettings.cs @@ -20,10 +20,7 @@ namespace Microsoft.Kusto.ServiceLayer.SqlContext { get { - if (this.sqlTools == null) - { - this.sqlTools = new CompoundToolsSettingsValues(MssqlTools, AllSqlTools); - } + this.sqlTools ??= new CompoundToolsSettingsValues(MssqlTools, AllSqlTools); return this.sqlTools; } set @@ -40,10 +37,7 @@ namespace Microsoft.Kusto.ServiceLayer.SqlContext { get { - if (this.mssqlTools == null) - { - this.mssqlTools = new SqlToolsSettingsValues(false); - } + this.mssqlTools ??= new SqlToolsSettingsValues(false); return this.mssqlTools; } set @@ -60,10 +54,7 @@ namespace Microsoft.Kusto.ServiceLayer.SqlContext { get { - if (this.allSqlTools == null) - { - this.allSqlTools = new SqlToolsSettingsValues(false); - } + this.allSqlTools ??= new SqlToolsSettingsValues(false); return this.allSqlTools; } set diff --git a/src/Microsoft.Kusto.ServiceLayer/Utility/LongList.cs b/src/Microsoft.Kusto.ServiceLayer/Utility/LongList.cs index 0d5640ea..1d550201 100644 --- a/src/Microsoft.Kusto.ServiceLayer/Utility/LongList.cs +++ b/src/Microsoft.Kusto.ServiceLayer/Utility/LongList.cs @@ -85,12 +85,9 @@ namespace Microsoft.Kusto.ServiceLayer.Utility } else // need to split values into several arrays { - if (expandedList == null) - { - // very inefficient so delay as much as possible - // immediately add 0th array - expandedList = new List> {shortList}; - } + // very inefficient so delay as much as possible + // immediately add 0th array + expandedList ??= new List> {shortList}; int arrayIndex = (int)(Count / this.ExpandListSize); // 0 based diff --git a/src/Microsoft.SqlTools.Hosting/Extensibility/ExtensionServiceProvider.cs b/src/Microsoft.SqlTools.Hosting/Extensibility/ExtensionServiceProvider.cs index 6c3939d5..d9c07ac5 100644 --- a/src/Microsoft.SqlTools.Hosting/Extensibility/ExtensionServiceProvider.cs +++ b/src/Microsoft.SqlTools.Hosting/Extensibility/ExtensionServiceProvider.cs @@ -185,10 +185,7 @@ namespace Microsoft.SqlTools.Extensibility public IEnumerable GetExports() { - if (exports == null) - { - exports = host.GetExports(contractType).ToList(); - } + exports ??= host.GetExports(contractType).ToList(); return exports.Cast(); } diff --git a/src/Microsoft.SqlTools.ResourceProvider.DefaultImpl/AzureResourceWrapper.cs b/src/Microsoft.SqlTools.ResourceProvider.DefaultImpl/AzureResourceWrapper.cs index 5819127d..fdeb9fc9 100644 --- a/src/Microsoft.SqlTools.ResourceProvider.DefaultImpl/AzureResourceWrapper.cs +++ b/src/Microsoft.SqlTools.ResourceProvider.DefaultImpl/AzureResourceWrapper.cs @@ -78,10 +78,7 @@ namespace Microsoft.SqlTools.ResourceProvider.DefaultImpl public string ResourceGroupName { get { - if (this.resourceGroupName == null) - { - this.resourceGroupName = ParseResourceGroupNameFromId(); - } + this.resourceGroupName ??= ParseResourceGroupNameFromId(); return this.resourceGroupName ?? string.Empty; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs index 81d33d0c..02c48d03 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs @@ -42,10 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { get { - if (AdminService.connectionService == null) - { - AdminService.connectionService = ConnectionService.Instance; - } + AdminService.connectionService ??= ConnectionService.Instance; return AdminService.connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs index 2fbe3075..3a5a93d9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs @@ -51,10 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs index 3dd7e697..d7825cc2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs @@ -8,6 +8,7 @@ using System.Data; using System.Collections.Generic; using Microsoft.SqlServer.Management.Smo.Agent; using Microsoft.SqlTools.ServiceLayer.Agent.Contracts; +using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.Agent { @@ -261,7 +262,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent // Add steps to the job if any var jobSteps = new List(); - foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries) + foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries.Cast()) { if (steps.Contains(subEntry.StepName)) { @@ -303,7 +304,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent // Add steps to the job if any var jobSteps = new List(); - foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries) + foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries.Cast()) { if (steps.Contains(subEntry.StepName)) { diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/LogAggregator.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/LogAggregator.cs index 100c3d05..1d748291 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/LogAggregator.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/LogAggregator.cs @@ -416,10 +416,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { e.Source = sourceName; - if (m_exceptionList == null) - { - m_exceptionList = new List(); - } + m_exceptionList ??= new List(); m_exceptionList.Add(e); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs index 93c9230b..ac7efcc9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs @@ -8,6 +8,7 @@ using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Globalization; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using Microsoft.SqlServer.Management.Common; @@ -677,7 +678,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this); - foreach (Match match in matches) + foreach (Match match in matches.Cast()) { string propertyName = match.Groups["property"].Value; PropertyDescriptor property = properties[propertyName]; diff --git a/src/Microsoft.SqlTools.ServiceLayer/AutoParameterizaition/TsqlMultiVisitor.cs b/src/Microsoft.SqlTools.ServiceLayer/AutoParameterizaition/TsqlMultiVisitor.cs index bb0f847f..838057e6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/AutoParameterizaition/TsqlMultiVisitor.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/AutoParameterizaition/TsqlMultiVisitor.cs @@ -31,11 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.AutoParameterizaition { get { - if (_executionParameters == null) - { - _executionParameters = new Dictionary(); - } - + _executionParameters ??= new Dictionary(); return _executionParameters; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Cms/CmsService.cs b/src/Microsoft.SqlTools.ServiceLayer/Cms/CmsService.cs index b3415969..338334a9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Cms/CmsService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Cms/CmsService.cs @@ -356,10 +356,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 80cf7c71..528b6eca 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -84,10 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection { get { - if (lockedDatabaseManager == null) - { - lockedDatabaseManager = DatabaseLocksManager.Instance; - } + lockedDatabaseManager ??= DatabaseLocksManager.Instance; return lockedDatabaseManager; } set @@ -216,10 +213,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection { get { - if (this.connectionFactory == null) - { - this.connectionFactory = new SqlConnectionFactory(); - } + this.connectionFactory ??= new SqlConnectionFactory(); return this.connectionFactory; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs index 583767c6..ecb90d98 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs @@ -347,10 +347,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx { get { - if (sqlTaskManagerInstance == null) - { - sqlTaskManagerInstance = SqlTaskManager.Instance; - } + sqlTaskManagerInstance ??= SqlTaskManager.Instance; return sqlTaskManagerInstance; } set @@ -366,10 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs index 4e7578c7..cd878255 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs @@ -52,10 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set @@ -68,10 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { get { - if (sqlTaskManagerInstance == null) - { - sqlTaskManagerInstance = SqlTaskManager.Instance; - } + sqlTaskManagerInstance ??= SqlTaskManager.Instance; return sqlTaskManagerInstance; } set @@ -87,10 +81,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { get { - if (fileBrowserService == null) - { - fileBrowserService = FileBrowserService.Instance; - } + fileBrowserService ??= FileBrowserService.Instance; return fileBrowserService; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/ConditionParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/ConditionParser.cs index 97d32810..a43f6bb2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/ConditionParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/ConditionParser.cs @@ -43,10 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (conditionParser == null) - { - conditionParser = new ConditionParser(); - } + conditionParser ??= new ConditionParser(); return conditionParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorOperationParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorOperationParser.cs index 5a269b5f..39e0dae6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorOperationParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorOperationParser.cs @@ -67,10 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (cursorOperationParser == null) - { - cursorOperationParser = new CursorOperationParser(); - } + cursorOperationParser ??= new CursorOperationParser(); return cursorOperationParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorStatementParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorStatementParser.cs index e51b3acc..ddb88219 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorStatementParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/CursorStatementParser.cs @@ -19,10 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { object cursorType = node["CursorActualType"]; - if (cursorType == null) - { - cursorType = node["StatementType"]; - } + cursorType ??= node["StatementType"]; Operation cursor = cursorType != null ? OperationTable.GetCursorType(cursorType.ToString()) @@ -46,10 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (cursorStatementParser == null) - { - cursorStatementParser = new CursorStatementParser(); - } + cursorStatementParser ??= new CursorStatementParser(); return cursorStatementParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Edge.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Edge.cs index c8bcd748..8cfa7a6c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Edge.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Edge.cs @@ -101,10 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan get { object propertyValue = this["EstimateRows"]; - if (propertyValue == null) - { - propertyValue = this["StatementEstRows"]; - } + propertyValue ??= this["StatementEstRows"]; return propertyValue != null ? Convert.ToDouble(propertyValue, CultureInfo.CurrentCulture) : 0; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FilterTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FilterTypeParser.cs index b79ff1ad..ea89a974 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FilterTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FilterTypeParser.cs @@ -51,10 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (filterTypeParser == null) - { - filterTypeParser = new FilterTypeParser(); - } + filterTypeParser ??= new FilterTypeParser(); return filterTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FunctionTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FunctionTypeParser.cs index 5c7721e9..a540eea9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FunctionTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/FunctionTypeParser.cs @@ -80,10 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (functionTypeParser == null) - { - functionTypeParser = new FunctionTypeParser(); - } + functionTypeParser ??= new FunctionTypeParser(); return functionTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/IndexOpTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/IndexOpTypeParser.cs index e03d0859..c3eef748 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/IndexOpTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/IndexOpTypeParser.cs @@ -28,10 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (indexOpTypeParser == null) - { - indexOpTypeParser = new IndexOpTypeParser(); - } + indexOpTypeParser ??= new IndexOpTypeParser(); return indexOpTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/MergeTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/MergeTypeParser.cs index fe031723..380046db 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/MergeTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/MergeTypeParser.cs @@ -65,10 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (mergeTypeParser == null) - { - mergeTypeParser = new MergeTypeParser(); - } + mergeTypeParser ??= new MergeTypeParser(); return mergeTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs index 42ea2667..48a05dd6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/Node.cs @@ -36,10 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan this.LogicalOpUnlocName = null; this.PhysicalOpUnlocName = null; this.root = context.Graph.Root; - if (this.root == null) - { - this.root = this; - } + this.root ??= this; this.Graph = context.Graph; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/OperationTable.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/OperationTable.cs index b2270b52..30d74862 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/OperationTable.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/OperationTable.cs @@ -6,7 +6,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Reflection; +using System.Xml.Serialization; namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { @@ -372,7 +374,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan if (member.Name == enumMemberName) { object[] attributes = member.GetCustomAttributes(typeof(System.Xml.Serialization.XmlEnumAttribute), true); - foreach (System.Xml.Serialization.XmlEnumAttribute attribute in attributes) + foreach (System.Xml.Serialization.XmlEnumAttribute attribute in attributes.Cast()) { return attribute.Name; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyValue.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyValue.cs index 550b8abe..40ac2ea2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyValue.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/PropertyValue.cs @@ -139,11 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan if (this.displayName != null || this.displayNameKey != null) { - if (this.displayName == null) - { - this.displayName = SR.Keys.GetString(this.displayNameKey); - } - + this.displayName ??= SR.Keys.GetString(this.displayNameKey); return this.displayName; } @@ -159,11 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan if (this.description != null || this.descriptionKey != null) { - if (this.description == null) - { - this.description = SR.Keys.GetString(this.descriptionKey); - } - + this.description ??= SR.Keys.GetString(this.descriptionKey); return this.description; } @@ -188,10 +180,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { this.displayNameKey = displayNameDescriptionAttribute.DisplayName; this.descriptionKey = displayNameDescriptionAttribute.Description; - if (this.descriptionKey == null) - { - this.descriptionKey = this.displayNameKey; - } + this.descriptionKey ??= this.displayNameKey; } DisplayOrderAttribute displayOrderAttribute = diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpBaseTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpBaseTypeParser.cs index b4e4bb88..6ad2407e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpBaseTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpBaseTypeParser.cs @@ -40,9 +40,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan object value = relOpProperty.GetValue(parsedItem); if (value != null) { - if (value is IEnumerable) + if (value is IEnumerable enumerable) { - foreach (object item in (IEnumerable)value) + foreach (object item in enumerable) { yield return item; } @@ -72,10 +72,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (relOpBaseTypeParser == null) - { - relOpBaseTypeParser = new RelOpBaseTypeParser(); - } + relOpBaseTypeParser ??= new RelOpBaseTypeParser(); return relOpBaseTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpTypeParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpTypeParser.cs index a75424b2..4843cb88 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpTypeParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/RelOpTypeParser.cs @@ -722,10 +722,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (relOpTypeParser == null) - { - relOpTypeParser = new RelOpTypeParser(); - } + relOpTypeParser ??= new RelOpTypeParser(); return relOpTypeParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/StatementParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/StatementParser.cs index a91a3a9f..a5ffacff 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/StatementParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/StatementParser.cs @@ -133,10 +133,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (statementParser == null) - { - statementParser = new StatementParser(); - } + statementParser ??= new StatementParser(); return statementParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanHierarchyParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanHierarchyParser.cs index 69760c3d..f37ddb25 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanHierarchyParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanHierarchyParser.cs @@ -56,10 +56,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { get { - if (xmlPlanHierarchyParser == null) - { - xmlPlanHierarchyParser = new XmlPlanHierarchyParser(); - } + xmlPlanHierarchyParser ??= new XmlPlanHierarchyParser(); return xmlPlanHierarchyParser; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanNodeBuilder.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanNodeBuilder.cs index bb7c9dae..5dc2438d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanNodeBuilder.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanNodeBuilder.cs @@ -12,6 +12,7 @@ using System.Xml; using System.Text; using System.Xml.Serialization; using System.Reflection; +using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { @@ -40,10 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan public ShowPlanGraph[] Execute(object dataSource) { ShowPlanXML plan = dataSource as ShowPlanXML; - if (plan == null) - { - plan = ReadXmlShowPlan(dataSource); - } + plan ??= ReadXmlShowPlan(dataSource); List graphs = new List(); int statementIndex = 0; @@ -238,7 +236,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { ArrayList targetStatementList = new ArrayList(); - foreach (BaseStmtInfoType statement in statementBlock.Items) + foreach (BaseStmtInfoType statement in statementBlock.Items.Cast()) { targetStatementList.Add(statement); @@ -264,7 +262,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan //add this element and its children if (stmtThen.Statements != null && stmtThen.Statements.Items != null) { - foreach (BaseStmtInfoType subStatement in stmtThen.Statements.Items) + foreach (BaseStmtInfoType subStatement in stmtThen.Statements.Items.Cast()) { targetStatementList.Add(subStatement); FlattenConditionClauses(subStatement, targetStatementList); @@ -280,7 +278,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan //add this element and its children if (stmtElse.Statements != null && stmtElse.Statements.Items != null) { - foreach (BaseStmtInfoType subStatement in stmtElse.Statements.Items) + foreach (BaseStmtInfoType subStatement in stmtElse.Statements.Items.Cast()) { targetStatementList.Add(subStatement); FlattenConditionClauses(subStatement, targetStatementList); @@ -302,7 +300,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { ArrayList targetStatementList = new ArrayList(); - foreach (BaseStmtInfoType statement in statementBlock.Items) + foreach (BaseStmtInfoType statement in statementBlock.Items.Cast()) { targetStatementList.Add(statement); @@ -351,7 +349,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan // Call itself recursively. if (functionItem.Function.Statements != null && functionItem.Function.Statements.Items != null) { - foreach (BaseStmtInfoType functionStatement in functionItem.Function.Statements.Items) + foreach (BaseStmtInfoType functionStatement in functionItem.Function.Statements.Items.Cast()) { ExtractFunctions(functionStatement, targetStatementList); } @@ -369,7 +367,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan { if (statementBlock != null && statementBlock.Items != null) { - foreach (BaseStmtInfoType statement in statementBlock.Items) + foreach (BaseStmtInfoType statement in statementBlock.Items.Cast()) { yield return statement; } @@ -402,10 +400,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan // check Memory Optimized table. bool memoryOptimzed = false; XmlNode scan = rootNode.SelectSingleNode("descendant::shp:IndexScan", nsMgr); - if (scan == null) - { - scan = rootNode.SelectSingleNode("descendant::shp:TableScan", nsMgr); - } + scan ??= rootNode.SelectSingleNode("descendant::shp:TableScan", nsMgr); + if (scan != null && scan.Attributes["Storage"] != null) { if (0 == string.Compare(scan.Attributes["Storage"].Value, "MemoryOptimized", StringComparison.Ordinal)) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanParser.cs b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanParser.cs index 697045ba..d4e1e404 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanParser.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ExecutionPlan/ShowPlan/XmlPlanParser.cs @@ -155,10 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan /// Node being parsed. protected virtual void SetNodeSpecialProperties(Node node) { - if (node.Operation == null) - { - node.Operation = GetNodeOperation(node); - } + node.Operation ??= GetNodeOperation(node); // Retrieve Subtree cost for this node node.SubtreeCost = GetNodeSubtreeCost(node); @@ -242,9 +239,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan.ShowPlan continue; } - if (value is IEnumerable) + if (value is IEnumerable enumerable) { - foreach (object item in (IEnumerable)value) + foreach (object item in enumerable) { if (XmlPlanParserFactory.GetParser(item.GetType()) != null) { diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageExtensibility/ExternalLanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageExtensibility/ExternalLanguageService.cs index d1fabce6..5763466b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageExtensibility/ExternalLanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageExtensibility/ExternalLanguageService.cs @@ -36,10 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Completion/CompletionService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Completion/CompletionService.cs index 9de595d3..4c0c1ede 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Completion/CompletionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Completion/CompletionService.cs @@ -37,10 +37,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion { get { - if(this.sqlParserWrapper == null) - { - this.sqlParserWrapper = new SqlParserWrapper(); - } + this.sqlParserWrapper ??= new SqlParserWrapper(); return this.sqlParserWrapper; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingContext.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingContext.cs index edb7d312..84820746 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingContext.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/ConnectedBindingContext.cs @@ -169,14 +169,11 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { get { - if (this.parseOptions == null) - { - this.parseOptions = new ParseOptions( + this.parseOptions ??= new ParseOptions( batchSeparator: LanguageService.DefaultBatchSeperator, isQuotedIdentifierSet: true, compatibilityLevel: DatabaseCompatibilityLevel, transactSqlVersion: TransactSqlVersion); - } return this.parseOptions; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index e2d3b769..5d6a1163 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -191,10 +191,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { get { - if (workspaceServiceInstance == null) - { - workspaceServiceInstance = WorkspaceService.Instance; - } + workspaceServiceInstance ??= WorkspaceService.Instance; return workspaceServiceInstance; } set @@ -207,10 +204,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { get { - if (this.serviceHostInstance == null) - { - this.serviceHostInstance = ServiceHost.Instance; - } + this.serviceHostInstance ??= ServiceHost.Instance; return this.serviceHostInstance; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs index c03769de..6a3da61f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/DataContainer.cs @@ -101,11 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Management { get { - if (m_hashTable == null) - { - m_hashTable = new Hashtable(); - } - + m_hashTable ??= new Hashtable(); return m_hashTable; } } @@ -808,11 +804,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management throw new InvalidOperationException(); } - if (m_server == null) - { - // NOTE: ServerConnection property will constuct the object if needed - m_server = new Server(ServerConnection); - } + // NOTE: ServerConnection property will constuct the object if needed + m_server ??= new Server(ServerConnection); } else if (this.serverType == ServerType.SQLCE) { @@ -933,10 +926,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Management public string GetDocumentPropertyString(string propertyName) { object result = GetDocumentPropertyValue(propertyName); - if (result == null) - { - result = string.Empty; - } + result ??= string.Empty; return (string)result; } @@ -1203,10 +1193,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Management bool databaseExists = false, XmlDocument containerDoc = null) { - if (containerDoc == null) - { - containerDoc = CreateDataContainerDocument(connInfo, databaseExists); - } + containerDoc ??= CreateDataContainerDocument(connInfo, databaseExists); var serverConnection = ConnectionService.OpenServerConnection(connInfo, "DataContainer"); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/IManagedConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/IManagedConnection.cs index 35d32df8..8b776718 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/IManagedConnection.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/IManagedConnection.cs @@ -95,24 +95,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Management this.connection = (SqlOlapConnectionInfoBase)cloneable.Clone(); this.closeOnDispose = true; } - else if (sourceConnection is SqlConnectionInfoWithConnection) + else if (sourceConnection is SqlConnectionInfoWithConnection connection2) { - this.connection = ((SqlConnectionInfoWithConnection)sourceConnection).Copy(); + this.connection = connection2.Copy(); this.closeOnDispose = true; } } } // if everything else has failed just use to passed in connection. - if (this.connection == null) - { - this.connection = sourceConnection; - } + this.connection ??= sourceConnection; // always set the lock timeout to prevent the shell from not responding - if (this.connection is SqlConnectionInfoWithConnection) + if (this.connection is SqlConnectionInfoWithConnection connection1) { // set lock_timeout to 10 seconds - ((SqlConnectionInfoWithConnection)this.connection).ServerConnection.LockTimeout = 10; + connection1.ServerConnection.LockTimeout = 10; } } #endregion @@ -190,10 +187,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Management { get { - if (activeConnections == null) - { - activeConnections = new Hashtable(); - } + activeConnections ??= new Hashtable(); return activeConnections; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/ManagementActionBase.cs b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/ManagementActionBase.cs index c2de9201..79ad3a58 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/ManagementActionBase.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/ManagementActionBase.cs @@ -94,19 +94,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Management } // allow to be sited only once - if (this.serviceProvider == null) - { - // cache the service provider - this.serviceProvider = sp; + // cache the service provider + this.serviceProvider ??= sp; - // call protected virtual method to enable derived classes to do initialization - // OnHosted(); - } + // call protected virtual method to enable derived classes to do initialization + // OnHosted(); } -#endregion + #endregion -#region IExecutionAwareManagementAction implementation + #region IExecutionAwareManagementAction implementation /// /// called before management action executes onRun method. @@ -502,10 +499,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Management { get { - if (this.cachedExecutionHandlerDelegate == null) - { - this.cachedExecutionHandlerDelegate = new ExecutionHandlerDelegate(this); - } + this.cachedExecutionHandlerDelegate ??= new ExecutionHandlerDelegate(this); return this.cachedExecutionHandlerDelegate; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/Utils.cs b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/Utils.cs index 498b0855..ab2f5c5c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Management/Common/Utils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Management/Common/Utils.cs @@ -32,11 +32,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management { //first, see if the object implemented this interface to override standard behavior System.Reflection.ICustomAttributeProvider attribProvider = objectToGetAttributeFrom as System.Reflection.ICustomAttributeProvider; - if (attribProvider == null) - { - //if not, get it from its type - attribProvider = (System.Reflection.ICustomAttributeProvider)objectToGetAttributeFrom.GetType(); - } + //if not, get it from its type + attribProvider ??= (System.Reflection.ICustomAttributeProvider)objectToGetAttributeFrom.GetType(); object[] attribs = attribProvider.GetCustomAttributes(customAttribute, true); if (attribs != null && attribs.Length > 0) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Metadata/MetadataService.cs b/src/Microsoft.SqlTools.ServiceLayer/Metadata/MetadataService.cs index 786b654e..4fac243b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Metadata/MetadataService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Metadata/MetadataService.cs @@ -33,10 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs b/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs index 5bbde169..dbcef7c8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Migration/MigrationService.cs @@ -75,10 +75,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/ModelManagement/ModelManagementService.cs b/src/Microsoft.SqlTools.ServiceLayer/ModelManagement/ModelManagementService.cs index 8cb04c79..4ceec814 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ModelManagement/ModelManagementService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ModelManagement/ModelManagementService.cs @@ -38,10 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ModelManagement { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs index 72cee108..81015fd1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs @@ -279,10 +279,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer internal async Task HandleFindNodesRequest(FindNodesParams findNodesParams, RequestContext context) { var foundNodes = FindNodes(findNodesParams.SessionId, findNodesParams.Type, findNodesParams.Schema, findNodesParams.Name, findNodesParams.Database, findNodesParams.ParentObjectNames); - if (foundNodes == null) - { - foundNodes = new List(); - } + foundNodes ??= new List(); + await context.SendResult(new FindNodesResponse { Nodes = foundNodes.Select(node => node.ToNodeInfo()).ToList() }); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/NodePathGenerator.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/NodePathGenerator.cs index a5750988..3a5b16fc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/NodePathGenerator.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/NodePathGenerator.cs @@ -70,10 +70,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel path = schema + "." + path; } - if (path == null) - { - path = ""; - } + path ??= ""; foreach (var matchingNode in matchingNodes) { diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs index 20abb50c..29c7ae20 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs @@ -53,10 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel { get { - if (smoWrapper == null) - { - smoWrapper = new SmoWrapper(); - } + smoWrapper ??= new SmoWrapper(); return smoWrapper; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs index f98db801..6a345da2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs @@ -55,10 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } @@ -144,11 +141,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler } catch { } - if (xeSession == null) - { - // create a new XEvent session and Profiler session - xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo); - } + // create a new XEvent session and Profiler session + xeSession ??= this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo); // start monitoring the profiler session monitor.StartMonitoringSession(parameters.OwnerUri, xeSession); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerSessionMonitor.cs b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerSessionMonitor.cs index b2726872..5da0bb41 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerSessionMonitor.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerSessionMonitor.cs @@ -76,10 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler lock (this.sessionsLock) { // start the monitoring thread - if (this.processorThread == null) - { - this.processorThread = Task.Factory.StartNew(ProcessSessions); - } + this.processorThread ??= Task.Factory.StartNew(ProcessSessions); // create new profiling session if needed if (!this.monitoredSessions.ContainsKey(session.Id)) diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs index 2ab6c0b6..79514aad 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/DataStorage/SaveAsExcelFileStreamWriterHelper.cs @@ -172,9 +172,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage AddCell((string)o); break; default: - if (o is TimeSpan) //TimeSpan doesn't have TypeCode + if (o is TimeSpan span) //TimeSpan doesn't have TypeCode { - AddCell((TimeSpan)o); + AddCell(span); } // We need to handle SqlDecimal and SqlMoney types here because we can't convert them to .NET types due to different precisons in SQL Server and .NET. else if (o is SqlDecimal || o is SqlMoney) @@ -518,10 +518,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage public ExcelSheet AddSheet(string sheetName = null) { string sheetFileName = "sheet" + (sheetNames.Count + 1); - if (sheetName == null) - { - sheetName = sheetFileName; - } + sheetName ??= sheetFileName; EnsureValidSheetName(sheetName); sheetNames.Add(sheetName); diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs index c92b24bc..ac0d4d91 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -72,13 +72,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution { get { - if (BufferFileStreamFactory == null) - { - BufferFileStreamFactory = new ServiceBufferFileStreamFactory + BufferFileStreamFactory ??= new ServiceBufferFileStreamFactory { QueryExecutionSettings = Settings.QueryExecutionSettings }; - } return BufferFileStreamFactory; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs index e15841b9..a7290ee7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs @@ -405,10 +405,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { get { - if (sqlTaskManagerInstance == null) - { - sqlTaskManagerInstance = SqlTaskManager.Instance; - } + sqlTaskManagerInstance ??= SqlTaskManager.Instance; return sqlTaskManagerInstance; } set @@ -421,10 +418,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs index 24b165aa..58d332df 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs @@ -15,6 +15,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts; using Microsoft.SqlTools.Utility; using Microsoft.SqlTools.ServiceLayer.Utility; +using System.Linq; namespace Microsoft.SqlTools.ServiceLayer.Scripting { @@ -43,10 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } set @@ -117,11 +115,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting } } - if (parameters.FilePath == null) - { - // Create a temporary and random path to handle this operation - parameters.FilePath = Path.GetTempFileName(); - } + // Create a temporary and random path to handle this operation + parameters.FilePath ??= Path.GetTempFileName(); if (!ShouldCreateScriptAsOperation(parameters)) { @@ -229,7 +224,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting { disposed = true; - foreach (ScriptingScriptOperation operation in this.ActiveOperations.Values) + foreach (ScriptingScriptOperation operation in this.ActiveOperations.Values.Cast()) { operation.Dispose(); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs b/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs index d6a7ee0b..dec38ad2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs @@ -47,10 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Security { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ServerConfigurations/ServerConfigService.cs b/src/Microsoft.SqlTools.ServiceLayer/ServerConfigurations/ServerConfigService.cs index 35ed474f..e0ec0ec4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ServerConfigurations/ServerConfigService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ServerConfigurations/ServerConfigService.cs @@ -37,10 +37,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations { get { - if (connectionService == null) - { - connectionService = ConnectionService.Instance; - } + connectionService ??= ConnectionService.Instance; return connectionService; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs index 77768987..3c7f0f06 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs @@ -20,10 +20,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext { get { - if (this.sqlTools == null) - { - this.sqlTools = new CompoundToolsSettingsValues(MssqlTools, AllSqlTools); - } + this.sqlTools ??= new CompoundToolsSettingsValues(MssqlTools, AllSqlTools); return this.sqlTools; } set @@ -40,10 +37,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext { get { - if (this.mssqlTools == null) - { - this.mssqlTools = new SqlToolsSettingsValues(false); - } + this.mssqlTools ??= new SqlToolsSettingsValues(false); return this.mssqlTools; } set @@ -60,10 +54,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext { get { - if (this.allSqlTools == null) - { - this.allSqlTools = new SqlToolsSettingsValues(false); - } + this.allSqlTools ??= new SqlToolsSettingsValues(false); return this.allSqlTools; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs index d9789494..d1fd5113 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/SmoScriptableOperationWithFullDbAccess.cs @@ -27,10 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices { get { - if (lockedDatabaseManager == null) - { - lockedDatabaseManager = ConnectionService.Instance.LockedDatabaseManager; - } + lockedDatabaseManager ??= ConnectionService.Instance.LockedDatabaseManager; return lockedDatabaseManager; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/TaskService.cs b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/TaskService.cs index a777afd1..2e52ea9a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TaskServices/TaskService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TaskServices/TaskService.cs @@ -36,10 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices { get { - if(taskManager == null) - { - taskManager = SqlTaskManager.Instance; - } + taskManager ??= SqlTaskManager.Instance; return taskManager; } set diff --git a/src/Microsoft.SqlTools.ServiceLayer/Utility/LongList.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/LongList.cs index 25d66110..fe8a3362 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Utility/LongList.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Utility/LongList.cs @@ -85,12 +85,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility } else // need to split values into several arrays { - if (expandedList == null) - { - // very inefficient so delay as much as possible - // immediately add 0th array - expandedList = new List> {shortList}; - } + // very inefficient so delay as much as possible + // immediately add 0th array + expandedList ??= new List> {shortList}; int arrayIndex = (int)(Count / this.ExpandListSize); // 0 based diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentTestUtils.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentTestUtils.cs index 5cb2893c..5c053568 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentTestUtils.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentTestUtils.cs @@ -357,10 +357,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent AgentNotebookInfo notebook = null) { var service = new AgentService(); - if (notebook == null) - { - notebook = GetTestNotebookInfo("myTestNotebookJob" + Guid.NewGuid().ToString(), "master"); - } + notebook ??= GetTestNotebookInfo("myTestNotebookJob" + Guid.NewGuid().ToString(), "master"); string tempNotebookPath = CreateTemplateNotebookFile(); await AgentNotebookHelper.CreateNotebook( diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DisasterRecovery/RestoreDatabaseServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DisasterRecovery/RestoreDatabaseServiceTests.cs index 5e2d3460..d10cf336 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DisasterRecovery/RestoreDatabaseServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DisasterRecovery/RestoreDatabaseServiceTests.cs @@ -50,18 +50,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery private async Task VerifyBackupFileCreated() { - if (fullBackupFilePath == null) - { - fullBackupFilePath = await CreateBackupFile(); - } + fullBackupFilePath ??= await CreateBackupFile(); } private async Task GetBackupFilesToRecoverDatabaseCreated() { - if (backupFilesToRecoverDatabase == null) - { - backupFilesToRecoverDatabase = await CreateBackupSetsToRecoverDatabase(); - } + backupFilesToRecoverDatabase ??= await CreateBackupSetsToRecoverDatabase(); return backupFilesToRecoverDatabase; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs index 5b30c4cf..0bc43a2d 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs @@ -283,10 +283,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests TestTimer timer = null, [CallerMemberName] string testName = "") { - if (timer == null) - { - timer = new TestTimer { PrintResult = false }; - } + timer ??= new TestTimer { PrintResult = false }; bool isReady = !waitForIntelliSense; await testService.ExecuteWithTimeout(timer, 550000, async () => { diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Baselined/BaselinedTest.cs b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Baselined/BaselinedTest.cs index 2626fbf0..6132191c 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Baselined/BaselinedTest.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/Baselined/BaselinedTest.cs @@ -146,8 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common.Baselined { get { - if (this._baselineSubDir == null) - this._baselineSubDir = string.Empty; + this._baselineSubDir ??= string.Empty; return this._baselineSubDir; } set { this._baselineSubDir = value; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs index 4baa8091..a394c2d9 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestLogger.cs @@ -65,10 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common { get { - if (pendingVerifications == null) - { - pendingVerifications = new List(); - } + pendingVerifications ??= new List(); return pendingVerifications; } set => pendingVerifications = value; diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Program.cs b/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Program.cs index 45cc7f17..17e75e16 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Program.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestEnvConfig/Program.cs @@ -13,6 +13,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestEnvConfig { class Program { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0210:Convert to top-level statements", Justification = "Structure retained for readability.")] static void Main(string[] args) { if (args.Length == 1) diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Messaging/MessageReaderTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Messaging/MessageReaderTests.cs index 9c5fe71a..6ac2ccc6 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Messaging/MessageReaderTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Messaging/MessageReaderTests.cs @@ -236,10 +236,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging private byte[] GetMessageBytes(string messageString, Encoding encoding = null) { - if (encoding == null) - { - encoding = Encoding.UTF8; - } + encoding ??= Encoding.UTF8; byte[] messageBytes = Encoding.UTF8.GetBytes(messageString); byte[] headerBytes = Encoding.ASCII.GetBytes(string.Format(Constants.ContentLengthFormatString, messageBytes.Length)); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ServiceHost/ScriptFileTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ServiceHost/ScriptFileTests.cs index 36699dba..9ac68f26 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ServiceHost/ScriptFileTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ServiceHost/ScriptFileTests.cs @@ -24,10 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost public static ScriptFile GetTestScriptFile(string initialText = null) { - if (initialText == null) - { - initialText = ScriptFileTests.query; - } + initialText ??= ScriptFileTests.query; string ownerUri = System.IO.Path.GetTempFileName(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs index be67b75d..a218043e 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs @@ -68,10 +68,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility { throw new TestDbException(); } - if (RowEnumerator == null) - { - RowEnumerator = ResultSetEnumerator.Current.GetEnumerator(); - } + RowEnumerator ??= ResultSetEnumerator.Current.GetEnumerator(); return RowEnumerator.MoveNext(); }